要匹配的源文:*********
target="countsmain">
2009058</a>
*********代码:
Regex regexarticles = new Regex("target=\"countsmain\">\\s\\S(?<dt>\\d+)</a>");
            MatchCollection marticles = regexarticles.Matches(htmlcode);老是匹配不成功,没发现有啥问题,郁闷.

解决方案 »

  1.   

    new Regex("target=\"countsmain\">\\s*(?<dt>\\d+)</a>");
      

  2.   


    //仅供参考
                String str = @"*********
                            target=""countsmain"">
                            2009058 </a>
                            *********";            Regex objRegex = new Regex(@"(?im)target=""countsmain"">\s*(\d+)\s*<\/a>");            MatchCollection objMatches = objRegex.Matches(str);            Response.Write("Result :<br />");            Int32 index = 0;            foreach (Match objMatch in objMatches)
                {
                    Response.Write(String.Format("{0} : {1}<br />", ++index, objMatch.Result("$1")));
                }
    //结果:
    /*
    Result :
    1 : 2009058
    */