<div class="blue14fontbold" id="new_page"><span><img height="11" width="6" src="http://www.m1905.com/m_images/images/pageleft.jpg">&nbsp;&nbsp;</span><span>总数:<b>23</b></span>&nbsp;&nbsp;<a class="pre" href="http://www.m1905.com/yx/film/c1p0.html">上一页</a><u><b>1</b></u> <a href="http://www.m1905.com/yx/film/c1p2.html">2</a> <a href="http://www.m1905.com/yx/film/c1p3.html">3</a> <a class="next" href="http://www.m1905.com/yx/film/c1p2.html">下一页</a><span>&nbsp;&nbsp;<img height="11" width="6" src="http://www.m1905.com/m_images/images/pageright.jpg"></span>
</div>
如上所示:用正则表达式匹配 <a href="http://www.m1905.com/yx/film/c1p2.html">2</a> <a href="http://www.m1905.com/yx/film/c1p3.html">3</a>这部分内容里a标签href上的内容 即:http://www.m1905.com/yx/film/c1p2.html

解决方案 »

  1.   


                Dictionary<string, string> dic = new Dictionary<string, string>();
                MatchCollection m = Regex.Matches(input, @"(?i)<a[^href]*\s*href=""([^>]+)"">(.*?)</a>");
                foreach (Match mx in m)
                {              
                    dic.Add(mx.Groups[1].Value, mx.Groups[2].Value);
                    Console.WriteLine(mx.Groups[1].Value + "\t" + mx.Groups[2].Value);
                }
    /*
     http://www.m1905.com/yx/film/c1p2.html    2
     http://www.m1905.com/yx/film/c1p3.html    3
    */
      

  2.   

    foreach(Match match in Regex.Matches(@"(?is)<a\s+href=""(.+?)"">"))
        Response.Write(match.Groups[1].Value+"<br/>");