public NextMatch ( ) : System.Text.RegularExpressions.Match | ||
return | System.Text.RegularExpressions.Match |
string input = "A quick brown fox jumps over the lazy dog"; string pattern = @"\b\w{5}\b"; //Matches any word with 5 letters Match m = Regex.Match(input, pattern); while (m.Success) { Console.WriteLine(m.Value); m = m.NextMatch(); //Searches for the next word with 5 letters }
string input = "The quick brown fox jumps over the lazy dog"; string pattern = @"q\w*"; //Matches any word starting with 'q' Match m = Regex.Match(input, pattern); if (m.Success) { Console.WriteLine(m.Value); m = m.NextMatch(); //Searches for the next word starting with 'q' if (m.Success) Console.WriteLine(m.Value); }This example finds the first word in the input string that starts with 'q'. Once found, the m.NextMatch() method is called again to look for the next match starting with 'q'. In this case, there are only two matches, hence the if statement to ensure that the next match actually exists before outputting its value. Overall, the System.Text.RegularExpressions package provides a powerful set of tools to work with regular expressions in C#.
public NextMatch ( ) : System.Text.RegularExpressions.Match | ||
return | System.Text.RegularExpressions.Match |