Updated: February 2010
Represents the set of captures made by a single capturing group.
Assembly: System (in System.dll)
The collection is immutable (read-only) and has no public constructor. The object contains one or more Capture objects.
Instances of the class are returned by the following properties:
The Group::Captures property. Each member of the collection represents a substring captured by a capturing group. If a quantifier is not applied to a capturing group, the includes a single Capture object that represents the same captured substring as the Group object. If a quantifier is applied to a capturing group, the includes one Capture object for each captured substring, and the Group object provides information only about the last captured substring.
The Match.Captures property. In this case, the collection consists of a single Capture object that provides information about the match as a whole. That is, the object provides the same information as the Match object.
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 GetEnumerator method.
The following example compares the Capture objects in the object returned by the Group::Captures and Match.Captures properties. It also compares Group objects with the Capture objects in the returned by the Group::Captures property. The example uses the following two regular expressions to find matches in a single input string:
This regular expression pattern identifies a word that consists of one or more word characters, followed by either one or two non-word characters such as white space or punctuation. The regular expression does not include any capturing groups. The output from the example shows that both the Match object and the objects returned by the Group::Captures and Match.Captures properties contain information about the same match.
This regular expression pattern identifies the words in a sentence. The pattern defines a single capturing group that consists of one or more word characters followed by one or two non-word characters. The regular expression pattern uses the + quantifier to match one or more occurrences of this group. The output from this example shows that the Match object and the object returned by the Match.Captures property contain information about the same match. The second Group object, which corresponds to the only capturing group in the regular expression, identifies only the last captured string, whereas the object returned by the first capturing group's Group::Captures property includes all captured substrings.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.