日期:2014-05-18  浏览次数:20343 次

正则表达式获取html代码里的数据
<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




------解决方案--------------------
C# code
(?i)(?<=<a\shref=").*?(?=")

------解决方案--------------------
探讨
<div class="blue14fontbold" id="new_page"><span><img height="11" width="6" src="http://www.m1905.com/m_images/images/pageleft.jpg">&amp;nbsp;&amp;nbsp;</span><span>总数:

<b>23</b></span>&amp;nbsp;&am……

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