Skip to content
David Cumps
Exam 70-536 study notes

Group Class and GroupCollection Class

Part of my 2008 study notes for exam 70-536 (.NET Framework 2.0).

Overview

  • Contains the named and unnamed results of matches in a regex.
    • Unnamed results are numbered starting from 1 (group 0 is the entire match).

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]));

You May Also Like