有没有办法在C#中获取捕获的组的名称?如何获取C#Regex中捕获的组的名称?
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);
}
我想要得到这样的结果:
Group: [I don´t know what should go here], Value: 123456789 04/09/2009 999 Group: number, Value: 123456789 Group: date, Value: 04/09/2009 Group: code, Value: 999
谢谢!正是我想要的。我从来没有想过这将是在正则表达式对象:( – 2009-09-04 20:00:23