Regex::GetGroupNumbers Method ()
Returns an array of capturing group numbers that correspond to group names in an array.
Assembly: System (in System.dll)
Both unnamed and named capturing groups can be accessed by number. Unnamed groups are numbered from left to right starting with 1. (The capturing group in index 0 (zero) represents the match as a whole.) Named groups are then numbered from left to right starting with a number that is one greater than the number of unnamed capturing groups.
Referencing a group by its number instead of by string name can provide faster access.
The following example defines a regular expression, \b((?<word>\w+)\s*)+(?<end>[.?!]), that matches a sentence. The regular expression includes three capturing groups: an unnamed group that captures an individual word along with a space character that may follow it; a group named word that captures the individual words in the sentence; and a group named end that captures the punctuation that ends the sentence. The example calls the method to get the numbers of all capturing groups, and then displays their captured string. In addition, the GroupNameFromNumber method is used to indicate whether a particular numbered group corresponds to a named group.
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