System.Text.RegularExpressions.Group.Captures Property

Gets a collection of all the captures matched by the capturing group, in innermost-leftmost-first order (or innermost-rightmost-first order if the regular expression is modified with the RegexOptions.RightToLeft option). The collection may have zero or more items.

Syntax

public CaptureCollection Captures { get; }

Value

Documentation for this section has not yet been entered.

Remarks

If a quantifier is not applied to a capturing group, the collection returned by the Group.Captures property contains a single System.Text.RegularExpressions.Capture object that provides information about the same substring as the System.Text.RegularExpressions.Group object. This is illustrated in the following example. It defines a regular expression, \b(\w+)\b, that extracts a single word from a sentence. The System.Text.RegularExpressions.Group object captures the word "This", and the single object in the System.Text.RegularExpressions.CaptureCollection contains information about the same capture.

code reference: System.Text.RegularExpressions.Group.Captures#1

The real utility of the Group.Captures property occurs when a quantifier is applied to a capturing group so that the group captures multiple substrings in a single regular expression. In this case, the System.Text.RegularExpressions.Group object contains information about the last captured substring, whereas the Group.Captures property contains information about all the substrings captured by the group. In the following example, the regular expression \b(\w+\s*)+\. matches an entire sentence that ends in a period. The group (\w+\s*)+ captures the individual words in the collection. Because the System.Text.RegularExpressions.Group collection contains information only about the last captured substring, it captures the last word in the sentence, "sentence". However, each word captured by the group is available from the collection returned by the Group.Captures property.

code reference: System.Text.RegularExpressions.Group.Captures#2

Requirements

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