Regex.GroupNumberFromName(String) Method

Definition

Returns the group number that corresponds to the specified group name.

public:
 int GroupNumberFromName(System::String ^ name);
public int GroupNumberFromName(string name);
member this.GroupNumberFromName : string -> int
Public Function GroupNumberFromName (name As String) As Integer

Parameters

name
String

The group name to convert to the corresponding group number.

Returns

The group number that corresponds to the specified group name, or -1 if name is not a valid group name.

Exceptions

name is null.

Remarks

The GroupNumberFromName(String) 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.

Applies to

See also