System.Text.RegularExpressions.Match.Groups Property

Gets a collection of groups matched by the regular expression.

Syntax

public virtual GroupCollection Groups { get; }

Value

Documentation for this section has not yet been entered.

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 Match.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 portion of the regular expression, (\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 portion of the regular expression, (\d{3}-\d{4}). These two groups can then be retrieved from the System.Text.RegularExpressions.GroupCollection object that is returned by the Match.Groups property, as the following example shows.

code reference: System.Text.RegularExpressions.Match.Groups#1

The System.Text.RegularExpressions.GroupCollection object returned by the Match.Groups property always has at least one member. If the regular expression engine cannot find any matches in a particular input string, the Group.Success property of the single System.Text.RegularExpressions.Group object in the collection is set to false and the System.Text.RegularExpressions.Group object's Capture.Value property is set to string.Empty. If the regular expression engine can find a match, the first element of the System.Text.RegularExpressions.GroupCollection object returned by the Match.Groups property contains a string that matches the entire regular expression pattern. Each subsequent element represents a captured group, if the regular expression includes capturing groups. For more information, see the "Grouping Constructs and Regular Expression Objects" section of the Grouping Constructs in Regular Expressions article.

Requirements

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