Represents the set of successful matches found by iteratively applying a regular expression pattern to the input string.
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main ()
{
Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b",RegexOptions.Compiled | RegexOptions.IgnoreCase);
string text = "The the quick brown fox fox jumped over the lazy dog dog.";
MatchCollection matches = rx.Matches(text);
Console.WriteLine("{0} matches found in:\n {1}", matches.Count, text);
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
Console.WriteLine("'{0}' repeated at positions {1} and {2}",
groups["word"].Value,
groups[0].Index,
groups[1].Index);
}
}
}
Related examples in the same category