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

求一正则,写了好久没有成功
<div   style= "display:none; ">
<a   href= "http://ent.qq.com/a/20070618/000005.htm "   target= "_blank "> <img   src= "http://mat1.qq.com/ent/upday200703/06181.jpg "   width= "328 "   height= "240 "   border= "0 "   onMouseOver= "clearAuto(); "   onMouseOut= "setAuto() "   /> </a> </div>
<div   style= "display:none; ">
<a   href= "http://ent.qq.com/a/20070618/000013.htm "   target= "_blank "> <img   src= "http://mat1.qq.com/ent/upday200703/06182.jpg "   width= "328 "   height= "240 "   border= "0 "   onMouseOver= "clearAuto(); "   onMouseOut= "setAuto() "   /> </a> </div>
<div   style= "display:none; ">
<a   href= "http://ent.qq.com/a/20070618/000020.htm "   target= "_blank "> <img   src= "http://mat1.qq.com/ent/upday200703/06183.jpg "   width= "328 "   height= "240 "   border= "0 "   onMouseOver= "clearAuto(); "   onMouseOut= "setAuto() "   /> </a> </div>
<div   style= "display:none; ">

<a   href= "http://ent.qq.com/a/20070618/000017.htm "   target= "_blank "> <img   src= "http://mat1.qq.com/ent/upday200703/06184.jpg "   width= "328 "   height= "240 "   border= "0 "   onMouseOver= "clearAuto(); "   onMouseOut= "setAuto() "   /> </a> </div>

<div   style= "display:block; ">
<a   href= "http://ent.qq.com/a/20070618/000009.htm "   target= "_blank "> <img   src= "http://mat1.qq.com/ent/upday200703/06185.jpg "   width= "328 "   height= "240 "   border= "0 "   onMouseOver= "clearAuto(); "   onMouseOut= "setAuto() "   /> </a> </div>

这只是一个页面的一部分代码,   但   <a   href= "http://ent.qq.com/a/20070618/000009.htm "   target= "_blank "> <img   src= "http://mat1.qq.com/ent/upday200703/06185.jpg "   width= "328 "   height= "240 "   border= "0 "   onMouseOver= "clearAuto(); "   onMouseOut= "setAuto() "   /> </a> </div>
是唯一的,求这里的网址和图片,网址和图片是对应的

------解决方案--------------------
jf
------解决方案--------------------
可以先截取 <a href= "http://ent.qq.com/a/20070618/000009.htm " target= "_blank ">
然后在截取http://ent.qq.com/a/20070618/000009.htm
我这是比较笨的方法吧...刚学正则,等更好的方法
------解决方案--------------------
这个我试过了用你给的数据:

string strPattern=@ " <a(\s.*?)href=\042(? <Link> [^\042]+)(.*) <img src=\042(? <Text> [^\042]+)(.*) </a> ";

MatchCollection Matches=Regex.Matches(strPage,strPattern,RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);

foreach(Match NextMatch in Matches)
{
string strURLText=NextMatch.Groups[ "Text "].Value + "| "+ NextMatch.Groups[ "Link "].Value;
Response.Write(strURLText + " <br> ");

}
------解决方案-------------