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 64 times
0

Robert Harvey
- 178,213
- 47
- 333
- 501

Just a learner
- 26,690
- 50
- 155
- 234
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
- 178,213
- 47
- 333
- 501
-
1A counter example would prove that the option was effective (as opposed to by default). – Olivier Jacot-Descombes Jul 02 '19 at 17:46