Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| // <Snippet2> | |
| using System; | |
| using System.Text.RegularExpressions; | |
| public class Example | |
| { | |
| public static void Main() | |
| { | |
| string pattern = @"(?<duplicateWord>\w+)\s\k<duplicateWord>\W(?<nextWord>\w+)"; | |
| string input = "He said that that was the the correct answer."; | |
| foreach (Match match in Regex.Matches(input, pattern, RegexOptions.IgnoreCase)) | |
| Console.WriteLine("A duplicate '{0}' at position {1} is followed by '{2}'.", | |
| match.Groups["duplicateWord"].Value, match.Groups["duplicateWord"].Index, | |
| match.Groups["nextWord"].Value); | |
| } | |
| } | |
| // The example displays the following output: | |
| // A duplicate 'that' at position 8 is followed by 'was'. | |
| // A duplicate 'the' at position 22 is followed by 'correct'. | |
| // </Snippet2> |