[<a href="/article/show.php?itemid-19168/page-2.html">2</a>] 最后得到的字符串是2 分页

解决方案 »

  1.   

    ^*-[0-9]*[0-9].html$
    我感觉你不是想用正则的。
    你只是提出来那里的数字。
    str.LastIndexOf('-')
    str.IndexOf('.html')
    通过这样找到位置。
    然后把数字那里的字符串找出来即可。
      

  2.   

                string str = @"[<a href=""/article/show.php?itemid-19168/page-2.html"">2</a>][<a href=""/article/show.php?itemid-19168/page-2.html"">下一页</a>]";
                Regex reg = new Regex(@"(?is)(?<=\[\s*<a[^>]*?>).*?(?=</a>\])");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Value);
      

  3.   

    多谢大牛 在问一个 获得 /article/show.php?itemid-19168/page-2.html 怎么匹配
      

  4.   

                string str = @"[<a href=""/article/show.php?itemid-19168/page-2.html"">2</a>][<a href=""/article/show.php?itemid-19168/page-2.html"">下一页</a>]";
                Regex reg = new Regex(@"(?is)\[<a[^>]*?href=(['""\s]?)([^'""\s]+)\1[^>]*?>(.*?)</a>\]");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Groups[2].Value + "--" + m.Groups[3].Value);