C Sharp: Difference between revisions
No edit summary |
No edit summary |
||
Line 15: | Line 15: | ||
{ | { | ||
// Define a regular expression for repeated words. | // Define a regular expression for repeated words. | ||
Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b" | Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b"); | ||
// Define a test string. | // Define a test string. | ||
string text = "The the quick brown fox fox jumps over the lazy dog dog."; | string text = "The the quick brown fox fox jumps over the lazy dog dog."; | ||
// Find | // Find match. | ||
Match match = rx.Match(text); | |||
// | // Iterature through captures | ||
foreach (Capture c in match.captures) { | |||
Console.WriteLine("Captured {c.Value}"); | |||
} | } | ||
} | } |