Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| ' Visual Basic .NET Document | |
| Option Strict On | |
| ' <Snippet2> | |
| Imports System.Text.RegularExpressions | |
| Module Example | |
| Public Sub Main() | |
| Dim pattern As String = "(?<duplicateWord>\w+)\s\k<duplicateWord>\W(?<nextWord>\w+)" | |
| Dim input As String = "He said that that was the the correct answer." | |
| Console.WriteLine(Regex.Matches(input, pattern, RegexOptions.IgnoreCase).Count) | |
| For Each match As 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) | |
| Next | |
| End Sub | |
| End Module | |
| ' 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> |