Returns the group number that corresponds to the specified group name.
Assemblies: System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)
System (in System.dll)
- Type: System.String
The group name to convert to the corresponding group number.
Return ValueType: System.Int32
The group number that corresponds to the specified group name, or -1 if name is not a valid group name.
A regular expression pattern may contain either named or numbered capturing groups, which delineate subexpressions within a pattern match. Numbered groups are delimited by the syntax (subexpression) and are assigned numbers based on their order in the regular expression. Named groups are delimited by the syntax (?<name>subexpression) or (?'name'subexpression), where name is the name by which the subexpression will be identified. (For more information, see Grouping Constructs in Regular Expressions.) The method identifies both named groups and numbered groups by their ordinal positions in the regular expression. Ordinal position zero always represents the entire regular expression. All numbered groups are then counted before named groups, regardless of their actual position in the regular expression pattern.
If name is the string representation of a group number that is present in the regular expression pattern, the method returns that number. If name corresponds to a named capturing group that is present in the regular expression pattern, the method returns its corresponding number. The comparison of name with the group name is case-sensitive. If name does not correspond to the name of a capturing group or to the string representation of the number of a capturing group, the method returns -1.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, 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.