Represents the set of captures made by a single capturing group.
Assembly: System (in System.dll)
Thetype exposes the following members.
|Count||Gets the number of substrings captured by the group.|
|IsReadOnly||Gets a value that indicates whether the collection is read only.|
|IsSynchronized||Gets a value that indicates whether access to the collection is synchronized (thread-safe).|
|Item||Gets an individual member of the collection.|
|SyncRoot||Gets an object that can be used to synchronize access to the collection.|
|CopyTo||Copies all the elements of the collection to the given array beginning at the given index.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetEnumerator||Provides an enumerator that iterates through the collection.|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|AsParallel||Enables parallelization of a query. (Defined by ParallelEnumerable.)|
|AsQueryable||Converts an IEnumerable to an IQueryable. (Defined by Queryable.)|
|Cast(TResult)||Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)|
|OfType(TResult)||Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)|
|ICollection.CopyTo||Copies all the elements of the collection to the given array beginning at the given index.|
|ICollection.IsSynchronized||Gets a value that indicates whether access to the collection is synchronized (thread-safe).|
|ICollection.SyncRoot||Gets an object that can be used to synchronize access to the collection.|
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 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.