Match.Groups Property

Definition

Gets a collection of groups matched by the regular expression.

public:
 virtual property System::Text::RegularExpressions::GroupCollection ^ Groups { System::Text::RegularExpressions::GroupCollection ^ get(); };
public virtual System.Text.RegularExpressions.GroupCollection Groups { get; }
member this.Groups : System.Text.RegularExpressions.GroupCollection
Public Overridable ReadOnly Property Groups As GroupCollection

Property Value

The character groups matched by the pattern.

Remarks

A regular expression pattern can include subexpressions, which are defined by enclosing a portion of the regular expression pattern in parentheses. Every such subexpression forms a group. The Groups property provides access to information about those subexpression matches. For example, the regular expression pattern (\d{3})-(\d{3}-\d{4}), which matches North American telephone numbers, has two subexpressions. The first consists of the area code, which composes the first three digits of the telephone number. This group is captured by the first set of parentheses, (\d{3}). The second consists of the individual telephone number, which composes the last seven digits of the telephone number. This group is captured by the second set of parentheses, (\d{3}-\d{4}).

The GroupCollection object returned by the Groups property always has at least one member. If the regular expression engine cannot find any matches in a particular input string, the single Group object in the collection has its Group.Success property set to false and its Group.Value property set to Empty.

If the collection has more than one member, the first item in the collection is the same as the Match object (the entire match). Each subsequent member represents a captured group, if the regular expression includes capturing groups. Groups can be accessed by their integer index or, for named groups, by name.

Applies to