Match Class and MatchCollection Class

Overview

  • Contains the result of matches in a regex.

Examples

Scanning Text

string input = "Hello world! Hello!";
string regex = "(?<1>ll)";
 
for (Match m = Regex.Match(input, regex); m.Success; m = m.NextMatch())
{
    Console.WriteLine(m.Groups[1].Index + ": " + m.Groups[1]);
}

Formatting Text

string input = "[link=\"http://blog.cumps.be/starting-exam-70-536-study/\"]Starting Exam 70-536 Study[/link]";
string regex = @"\[link=""(?<link>((.|\n)*?))""\](?<text>((.|\n)*?))\[\/link\]";
 
Console.WriteLine(Regex.Match(input, regex).Result("${text}: ${link}"));