foreach (Capture cp in mc.Groups["low_bound"].Captures) { //do something with name and cp.value }
}
Regex testXpress = new Regex("(?<dd>)[\u4e00-\u9fa5]+"); Match mc = testXpress.Match("dsafdsa真大事fdsfgdsag国防生23423"); string xx = mc.Groups["dd"].Value;xx就是对应捕获组dd所捕获的值啊
这我知道。我不是要按名字去访问,而是要遍历所有的捕获组,然后根据名字去处理值。问题的关键在于,事先不知道有哪些命名捕获组,否则我就可以把组名写成一个数组去遍历了。it is also easy:GroupCollection groups = regex.Match(line).Groups;foreach (string groupName in regex.GetGroupNames()) { Console.WriteLine( "Group: {0}, Value: {1}", groupName, groups[groupName].Value); }
这我知道。我不是要按名字去访问,而是要遍历所有的捕获组,然后根据名字去处理值。问题的关键在于,事先不知道有哪些命名捕获组,否则我就可以把组名写成一个数组去遍历了。it is also easy:GroupCollection groups = regex.Match(line).Groups;foreach (string groupName in regex.GetGroupNames()) { Console.WriteLine( "Group: {0}, Value: {1}", groupName, groups[groupName].Value); }严重同意
{
foreach (Capture cp in mc.Groups["low_bound"].Captures)
{
//do something with name and cp.value
}
}
Match mc = testXpress.Match("dsafdsa真大事fdsfgdsag国防生23423");
string xx = mc.Groups["dd"].Value;xx就是对应捕获组dd所捕获的值啊
{
Console.WriteLine(
"Group: {0}, Value: {1}",
groupName,
groups[groupName].Value);
}
{
Console.WriteLine(
"Group: {0}, Value: {1}",
groupName,
groups[groupName].Value);
}严重同意