using System; using System.Text.RegularExpressions; class Example { static void match(string pat, string text) { // Instantiate the regular expression object. Regex r = new Regex(pat, RegexOptions.IgnoreCase); // Match the regular expression pattern against a text string. Match m = r.Match(text); int matchCount = 0; while (m.Success) { Console.WriteLine("Match"+ (++matchCount)); for (int i = 1; i <= 3; i++) { Group g = m.Groups[i]; Console.WriteLine("Group" + i + " = '" + g + "'"); } m = m.NextMatch(); } } static void Main() { string pat = @"(?:(
]+>)(\w+))?([\ _]{3,})"; match(pat, "
Street ___________________
"); match(pat, "
CAP |__|__|__|__|__| number ______
"); match(pat, "
City _____________________ State |__|__|
"); match(pat, "
City2 ____________________ State2 _____
"); } }