首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

求一正则,写了好久没有成功,该如何解决

2011-12-27 
求一正则,写了好久没有成功divstyle display:none ahref http://ent.qq.com/a/20070618/000005.h

求一正则,写了好久没有成功
<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> ");

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


<a\s[^> ]*href=([ ' "]*)(? <url> [^ " '\s]+)\1\starget=[ ' "]*_blank[ " ']*> <img\s[^> ]*src=([ " ']*)(? <src> [^ " '\s]+)\2[^> ]*onMouseOver= "clearAuto\(\); "\s*onMouseOut= "SetAuto\(\) "[^> ]*>


..........我的。。。
[解决办法]
lxcnn(过客)的方法不错,帮你测试了!

热点排行