[ <strong>39</strong> 主题 / 312 回复 ]</p>类似这样的,如何把这个39 和这个312 去出来呢。[ <strong></strong> 主题 /  回复 ]</p>这个三个在内容里都是唯一的,所以应该可以用来识别。没用过,谁给个例子学习一下。

解决方案 »

  1.   

    Regex ex = new Regex(@"\d+");
    MatchCollection ms = ex.Matches("[ <strong>39 </strong> 主题 / 312 回复 ] </p> ");
    foreach (Match m in ms)
    {
        Console.WriteLine(m.Value);
    }
      

  2.   

    谢谢。 不过这样符合的项就多了。
    可能要用两次正则,一次识别这个
    [ <strong>39 </strong> 主题 / 312 回复 ] </p>
    语句出来,然后再从这个语句里识别出数字。请问如何识别这个语句呢?
      

  3.   

    @"\[\s*<strong>\s*(?<a>\d+)\s*</strong>\s*主题\s*/\s*(?<b>\d+)\s*回复\s*\]"
    命名捕获组 a 和 b 即这所求。
      

  4.   


             //.. 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 即所求,具体是怎么实现的,谢谢。
      

  5.   


     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; ;
                }