GroupCollection::Item Property (String)
Enables access to a member of the collection by string index.
Assemblies: System (in System.dll)
System.Text.RegularExpressions (in System.Text.RegularExpressions.dll)
groupName can be either the name of a capturing group that is defined by the (?<name>) element in a regular expression, or the string representation of the number of a capturing group that is defined by a grouping construct. For more information about groups in regular expressions, see Grouping Constructs in Regular Expressions.
You can retrieve the names of all the captured groups in a Regex object by calling the Regex::GetGroupNames method. You can also map the numbers of capturing groups in a regular expression to their names by calling the Regex::GroupNameFromNumber method. Individual names from the array can then be passed to the property to retrieve the captured string.
If groupname is not the name of a capturing group in the collection, or if groupname is the name of a capturing group that has not been matched in the input string, the method returns a Group object whose Group::Success property is false and whose Group.Value property is String::Empty.
The following example defines a regular expression that consists of two named groups. The first group, numbers, captures one or more consecutive digits. The second group, letter, matches a single character. Because the regular expression engine looks for zero or one occurrence of the pattern defined by the numbers group, the numbers group is not always present even if a match is successful. The example then illustrates the result when the property is used to retrieve an unmatched group, a matched group, and a group that is not defined in the regular expression. The example defines a regular expression pattern (?<numbers>\d+)*(?<letter>\w)\k<letter>, which is interpreted as shown in the following table.
Match one or more occurrence of a decimal digit. Name this the numbers capturing group. Match this pattern either zero or one time.
Match a single word character. Name this the letter capturing group.
Match the string captured by the letter capturing group.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8