How can I find all the matches in a string using a regular expression run in C#?
I want to find all matches in the below example string. Example:
inputString: Hello (mail) byebye (time) how are you (mail) how are you (time)
I want to match (mail) and (time) from the example. Including parentheses( and ).
In attempting to solve this, I've writtent the following code.
string testString = @"(mail)|(time)";
Regex regx = new Regex(Regex.Escape(testString), RegexOptions.IgnoreCase);
List<string> mactches = regx.Matches(inputString).OfType<Match>().Select(m => m.Value).Distinct().ToList();
foreach (string match in mactches)
{
//Do something
}
Is the pipe(|) used for the logical OR condition?