Friday, November 19, 2010

Regex Matches in C#


static void Main(string[] args)
{
string sample = "Swedish field marshal ... fact that Gustav II father the Thirty Years' War";

Regex r = new Regex(@"JS_DisplayEntry\((\d*?)\)", RegexOptions.IgnoreCase);

MatchCollection collection = r.Matches(sample);

foreach (Match m in collection)
{
Console.WriteLine(m.Groups[1].Value);
}

Console.ReadLine();
}

No comments: