Returns the set of captured groups in a single match.
Assembly: System (in System.dll)
Returns the number of groups in the collection.
Gets a value that indicates whether the collection is read-only.
Gets a value that indicates whether access to theis synchronized (thread-safe).
Enables access to a member of the collection by integer index.
Enables access to a member of the collection by string index.
Gets an object that can be used to synchronize access to the.
Copies all the elements of the collection to the given array beginning at the given index.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)
Provides an enumerator that iterates through the collection.
Serves as the default hash function. (Inherited from Object.)
Returns a string that represents the current object.(Inherited from Object.)
Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)
The Group objects that provide information about captured groups in a regular expression match. The collection is immutable (read-only) and has no public constructor. A object is returned by the Match.Groups property.class is a zero-based collection class that consists of one or more
The collection contains one or more System.Text.RegularExpressions.Group objects. If the match is successful, the first element in the collection contains the Group object that corresponds to the entire match. Each subsequent element represents a captured group, if the regular expression includes capturing groups. Matches from numbered (unnamed) capturing groups appear in numeric order before matches from named capturing groups. If the match is unsuccessful, the collection contains a single System.Text.RegularExpressions.Group object whose Success property is false and whose Value property equals String.Empty. For more information, see the "Grouping Constructs and Regular Expression Objects" section in the Grouping Constructs in Regular Expressions article.
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. In addition, you can access individual numbered captured groups from the Item(Int32) property (the indexer in C#), and you can access individual named captured groups from the Item(String) property. Note that you can retrieve an array that contains the numbers and names of all capturing groups by calling the Regex.GetGroupNumbers and Regex.GetGroupNames methods, respectively. Both are instance methods and require that you instantiate a Regex object that represents the regular expression to be matched.
The following example uses a regular expression with capturing groups to extract information about trademarks and registered trademarks used in text. The regular expression pattern is \b(\w+?)([\u00AE\u2122]), which is interpreted as shown in the following table.
Look for a word boundary.
Look for one or more word characters. Together, these form the trademarked name. (Note that this regular expression assumes that a trademark consists of a single word.) This is the first capturing group.
Look for either the ® or the ™ character. This is the second capturing group.
For each match, the Group objects. The first object contains the string that matches the entire regular expression. The second object, which represents the first captured group, contains the product name. The third object, which represents the second captured group, contains the trademark or registered trademark symbol.contains three
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.