0

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.

Robert Harvey
  • 173,679
  • 45
  • 326
  • 490
Just a learner
  • 24,222
  • 49
  • 140
  • 218

1 Answers1

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