정규 표현식의 기초

Console.WriteLine(Regex.Match("color", @"colou?r").Success);  // True
Console.WriteLine(Regex.Match("colour", @"colou?r").Success);  // True
Console.WriteLine(Regex.Match("colouur", @"colou?r").Success);  // False
Match m = Regex.Match("any colour you like", @"colou?r");

Console.WriteLine(m.Success);  // True
Console.WriteLine(m.Index);  // 4
Console.WriteLine(m.Length);  // 6
Console.WriteLine(m.Value);  // colour
Console.WriteLine(m.ToString());  // colour
Match m1 = Regex.Match("One color? Threre are two colours in my head!", @"colou?rs?");
Match m2 = n1.NextMatch();
Console.WriteLine(m1);  // color
Console.WriteLine(m2);  // colour
foreach (Match m in Regex.Match("One color? Threre are two colours in my head!", @"colou?rs?"))
  Console.WriteLine(m);
Console.WriteLine(Regex.IsMatch("Jenny", "Jen(ny|nifer)?"));  // True

컴파일된 정규 표현식

Regex r = new Regex(@"sausages?", RegexOptions.Compiled);
Console.WriteLine(r.Match("sausage"));  // sausage
Console.WriteLine(r.Match("sausages"));  // sausages