本文整理匯總了C#中System.Text.RegularExpressions.Regex.GetGroupNumbers方法的典型用法代碼示例。如果您正苦於以下問題:C# Regex.GetGroupNumbers方法的具體用法?C# Regex.GetGroupNumbers怎麽用?C# Regex.GetGroupNumbers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.GetGroupNumbers方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\b((?<word>\w+)\s*)+(?<end>[.?!])";
string input = "This is a sentence. This is a second sentence.";
Regex rgx = new Regex(pattern);
int[] groupNumbers = rgx.GetGroupNumbers();
Match m = rgx.Match(input);
if (m.Success) {
Console.WriteLine("Match: {0}", m.Value);
foreach (var groupNumber in groupNumbers) {
string name = rgx.GroupNameFromNumber(groupNumber);
int number;
Console.WriteLine(" Group {0}{1}: '{2}'",
groupNumber,
! string.IsNullOrEmpty(name) &
! Int32.TryParse(name, out number) ?
" (" + name + ")" : String.Empty,
m.Groups[groupNumber].Value);
}
}
}
}
輸出:
Match: This is a sentence. Group 0: 'This is a sentence.' Group 1: 'sentence' Group 2 (word): 'sentence' Group 3 (end): '.'