Group Class and GroupCollection Class

Overview

  • Contains the named and unnamed results of matches in a regex.
    • Unnamed results are numbered starting from 1.

Examples

Scanning Text

string input = "The dog ate a bone.";
string regex = @"^The (?<animal>\w+)\b ate (?<food>.+)\.$";
 
Match m = Regex.Match(input, regex);
Console.WriteLine(string.Format("Animal: {0}, Food: {1}!", m.Groups["animal"], m.Groups[2]));