@"\[\s*<strong>\s*(?<a>\d+)\s*</strong>\s*主题\s*/\s*(?<b>\d+)\s*回复\s*\]" 命名捕获组 a 和 b 即这所求。
//.. reply = html sourccode Regex ex = new Regex(@"\[\s*<strong>\s*(?<a>\d+)\s*</strong>\s*主题\s*/\s*(?<b>\d+)\s*回复\s*\]"); MatchCollection ms = ex.Matches(reply); MessageBox.Show(ms[0].ToString());
Regex ex2 = new Regex(@"\d+"); MatchCollection ms2 = ex.Matches(ms[0].ToString()); MessageBox.Show(ms2[0].tostring()); MessageBox.Show(ms2[1].toString()); 得不到结果。 不知道 命名捕获组 a 和 b 即所求,具体是怎么实现的,谢谢。
MatchCollection ms = ex.Matches("[ <strong>39 </strong> 主题 / 312 回复 ] </p> ");
foreach (Match m in ms)
{
Console.WriteLine(m.Value);
}
可能要用两次正则,一次识别这个
[ <strong>39 </strong> 主题 / 312 回复 ] </p>
语句出来,然后再从这个语句里识别出数字。请问如何识别这个语句呢?
命名捕获组 a 和 b 即这所求。
//.. reply = html sourccode
Regex ex = new Regex(@"\[\s*<strong>\s*(?<a>\d+)\s*</strong>\s*主题\s*/\s*(?<b>\d+)\s*回复\s*\]");
MatchCollection ms = ex.Matches(reply); MessageBox.Show(ms[0].ToString());
Regex ex2 = new Regex(@"\d+");
MatchCollection ms2 = ex.Matches(ms[0].ToString());
MessageBox.Show(ms2[0].tostring());
MessageBox.Show(ms2[1].toString());
得不到结果。 不知道 命名捕获组 a 和 b 即所求,具体是怎么实现的,谢谢。
Regex reg1 = new Regex(@"<strong>(?<shuzi>.*?)</strong> 主题 /(?<reply>.*?)回复 ]", RegexOptions.IgnoreCase);
MatchCollection mc1 = reg1.Matches("<strong>39 </strong> 主题 / 312 回复 ]"); //设定要查找的字符串
foreach (Match m1 in mc1)
{
this.textBox1.Text += m1.Groups["shuzi"].Value +m1.Groups["reply"].Value + Environment.NewLine; ;
}