一个正则表达式问题,谁能解决?马上给份
--------------------编程问答-------------------- foreach(Match m in rx.Matches(youstring)){
m.Group["yue"].Value
} --------------------编程问答-------------------- 错了,你这是匹配到的内容
我要的是:(?<yue>\d+) 和:(?<nian>\d+)
--------------------编程问答-------------------- 少个了s
--------------------编程问答-------------------- 不明白什么意思。 --------------------编程问答-------------------- 既然使用了命名捕获组
foreach (Match m in Regex.Matches(str))
{
m.Groups["yue"].Value;
m.Groups["nian"].Value;
}
那就根据捕获组名称去获取值
rx.Match("").Groups["组名称"].Value --------------------编程问答-------------------- 我要的结果是返回:(?<yue>\d+) 和:(?<nian>\d+)
而不是匹配后的内容,不知道明白没有
--------------------编程问答-------------------- \(\?[^)]+?\) --------------------编程问答--------------------
我明白,不过这有什么意义? --------------------编程问答-------------------- 就是动态获这个Group的正则式,而不是匹配到的内容 --------------------编程问答-------------------- 喔 是要得到那两个字符串,这样?
string str = @"/news/(?<yue>\d+)/(?<nian>\d+)/show-100.aspx";
Regex reg = new Regex(@"(?i)\(\?[^\)]+\)");
foreach (Match m in reg.Matches(str))
Console.WriteLine(m.Value);
/*
(?<yue>\d+)
(?<nian>\d+)
*/
补充:.NET技术 , C#