日期:2014-05-18 浏览次数:20453 次
<div class="pagebox"><span class="pagebox_pre_nolink">上一页</span><span class="pagebox_num_nonce">1</span><span class="pagebox_num"><a target="_self" href="102641554-2.html" class="page">2</a></span><span class="pagebox_num"><a target="_self" href="102641554-3.html" class="page">3</a></span><span class="pagebox_num"><a target="_self" href="102641554-4.html" class="page">4</a></span><span class="pagebox_num"><a target="_self" href="102641554-5.html" class="page">5</a></span><span class="pagebox_next"><a href="102641554-2.html">下一页</a></span></div>
string str = @"<div class=""pagebox""><span class=""pagebox_pre_nolink"">上一页</span><span class=""pagebox_num_nonce"">1</span><span class=""pagebox_num""><a target=""_self"" href=""102641554-2.html"" class=""page"">2</a></span><span class=""pagebox_num""><a target=""_self"" href=""102641554-3.html"" class=""page"">3</a></span><span class=""pagebox_num""><a target=""_self"" href=""102641554-4.html"" class=""page"">4</a></span><span class=""pagebox_num""><a target=""_self"" href=""102641554-5.html"" class=""page"">5</a></span><span class=""pagebox_next""><a href=""102641554-2.html"">下一页</a></span></div>"; Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""\s]?)(?<url>[^'""\s]+)\1[^>]*?class=""page""[^>]*?>(?<text>.*?)</a>"); foreach (Match m in reg.Matches(str)) Console.WriteLine("{0} {1}", m.Groups["url"].Value, m.Groups["text"].Value);