System.Text.RegularExpressions.GroupCollection Class

Returns the set of captured groups in a single match.

See Also: GroupCollection Members


public class GroupCollection : ICollection


The System.Text.RegularExpressions.GroupCollection class consists of one or more System.Text.RegularExpressions.Group objects that provide information about captured groups in a regular expression match. The collection is immutable (read-only) and has no public constructor. A System.Text.RegularExpressions.GroupCollection object is returned by the Match.Groups property.

The collection contains one or more System.Text.RegularExpressions.Group objects. If the match is successful, the first element in the collection contains the System.Text.RegularExpressions.Group object that corresponds to the entire match. Each subsequent element represents a captured group, if the regular expression includes capturing groups. Matches from numbered (unnamed) capturing groups appear in numeric order before matches from named capturing groups. If the match is unsuccessful, the collection contains a single System.Text.RegularExpressions.Group object whose Group.Success property is false and whose Capture.Value property equals string.Empty. For more information, see the "Grouping Constructs and Regular Expression Objects" section in the Grouping Constructs in Regular Expressions article.

To iterate through the members of the collection, you should use the collection iteration construct provided by your language (such as foreach in C# and For Each…Next in Visual Basic) instead of retrieving the enumerator that is returned by the GroupCollection.GetEnumerator method.


Namespace: System.Text.RegularExpressions
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,,