Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| // <Snippet9> | |
| using System; | |
| using System.Text.RegularExpressions; | |
| public class Example | |
| { | |
| public static void Main() | |
| { | |
| string input = "This is one sentence. This is another."; | |
| string pattern = @"\b(?:\w+[;,]?\s?)+[.?!]"; | |
| foreach (Match match in Regex.Matches(input, pattern)) { | |
| Console.WriteLine("Match: '{0}' at index {1}.", | |
| match.Value, match.Index); | |
| int grpCtr = 0; | |
| foreach (Group grp in match.Groups) { | |
| Console.WriteLine(" Group {0}: '{1}' at index {2}.", | |
| grpCtr, grp.Value, grp.Index); | |
| int capCtr = 0; | |
| foreach (Capture cap in grp.Captures) { | |
| Console.WriteLine(" Capture {0}: '{1}' at {2}.", | |
| capCtr, cap.Value, cap.Index); | |
| capCtr++; | |
| } | |
| grpCtr++; | |
| } | |
| Console.WriteLine(); | |
| } | |
| } | |
| } | |
| // The example displays the following output: | |
| // Match: 'This is one sentence.' at index 0. | |
| // Group 0: 'This is one sentence.' at index 0. | |
| // Capture 0: 'This is one sentence.' at 0. | |
| // | |
| // Match: 'This is another.' at index 22. | |
| // Group 0: 'This is another.' at index 22. | |
| // Capture 0: 'This is another.' at 22. | |
| // </Snippet9> |