Some regular expression engines support embedding regex options directly inside the regex itself. Like (?i)is, which matches the string is ignoring cases. Does C# support this feature? I skimmed over the documentation at this page, but didn't find anything.
Asked
Active
Viewed 59 times
0
Robert Harvey
- 173,679
- 45
- 326
- 490
Just a learner
- 24,222
- 49
- 140
- 218
1 Answers
3
using System;
using System.Text.RegularExpressions;
class MainClass {
public static void Main (string[] args) {
string text = "is, IS";
string regex = "(?i)is";
MatchCollection matches = Regex.Matches(text, regex);
Console.WriteLine("{0} matches found in:\n {1}", matches.Count, text);
}
}
Output:
2 matches found in:
is, IS
Robert Harvey
- 173,679
- 45
- 326
- 490
-
1A counter example would prove that the option was effective (as opposed to by default). – Olivier Jacot-Descombes Jul 02 '19 at 17:46