Mega Code Archive

 
Categories / C# Book / 11 Regular Expression Basics
 

0639 Match class

The regular expressions engine works from left to right by default, so only the left-most match is returned. You can use the NextMatch method to return more matches: using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { Match m1 = Regex.Match("This is a test from rntsoft.com", @"2?s?"); Match m2 = m1.NextMatch(); Console.WriteLine(m1); Console.WriteLine(m2); } }