有没有办法在C#中获取捕获的组的名称?
string line = "No.123456789 04/09/2009 999";
Regex regex = new Regex(@"(?<number>[\d]{9}) (?<date>[\d]{2}/[\d]{2}/[\d]{4}) (?<code>.*)");
GroupCollection groups = regex.Match(line).Groups;
foreach (Group group in groups)
{
Console.WriteLine("Group: {0}, Value: {1}", ???, group.Value);
}
我想得到这个结果:
组:[我不知道该怎么办],值:123456789 04/09/2009 999 组:数字,值:123456789 组:日期,值:04/09/2009 组:代码,值:999