Поделиться через


Regex.GroupNumberFromName Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Text.RegularExpressions
Assembly:  System (in System.dll)

Syntax

'Declaration
Public Function GroupNumberFromName ( _
    name As String _
) As Integer
public int GroupNumberFromName(
    string name
)

Parameters

  • name
    Type: System.String
    The group name to convert to the corresponding group number.

Return Value

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

Exceptions

Exception Condition
ArgumentNullException

name is nulla null reference (Nothing in Visual Basic).

Remarks

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. The GroupNumberFromName 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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.