本文整理汇总了C#中System.Text.RegularExpressions.GroupCollection.Item属性的典型用法代码示例。如果您正苦于以下问题:C# GroupCollection.Item属性的具体用法?C# GroupCollection.Item怎么用?C# GroupCollection.Item使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Text.RegularExpressions.GroupCollection
的用法示例。
在下文中一共展示了GroupCollection.Item属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(\d+)*(\w)\2";
string input = "AA";
Match match = Regex.Match(input, pattern);
// Get the first named group.
Group group1 = match.Groups[1];
Console.WriteLine("Group 1 value: {0}", group1.Success ? group1.Value : "Empty");
// Get the second named group.
Group group2 = match.Groups[2];
Console.WriteLine("Group 2 value: {0}", group2.Success ? group2.Value : "Empty");
// Get a non-existent group.
Group group3 = match.Groups[3];
Console.WriteLine("Group 3 value: {0}", group3.Success ? group3.Value : "Empty");
}
}
输出:
Group 1 value: Empty Group 2 value: A Group 3 value: Empty
示例2: Main
//引入命名空间
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?<numbers>\d+)*(?<letter>\w)\k<letter>";
string input = "AA";
Match match = Regex.Match(input, pattern);
// Get the first named group.
Group group1 = match.Groups["numbers"];
Console.WriteLine("Group 'numbers' value: {0}", group1.Success ? group1.Value : "Empty");
// Get the second named group.
Group group2 = match.Groups["letter"];
Console.WriteLine("Group 'letter' value: {0}", group2.Success ? group2.Value : "Empty");
// Get a non-existent group.
Group group3 = match.Groups["none"];
Console.WriteLine("Group 'none' value: {0}", group3.Success ? group3.Value : "Empty");
}
}
输出:
Group 'numbers' value: Empty Group 'letter' value: A Group 'none' value: Empty