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
  • 178,213
  • 47
  • 333
  • 501
Just a learner
  • 26,690
  • 50
  • 155
  • 234

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
  • 178,213
  • 47
  • 333
  • 501