Regex.GroupNumberFromName Method (String)
Returns the group number that corresponds to the specified group name.
Assembly: System (in System.dll)
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.
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