读书人

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

发布时间: 2011-12-27 22:22:55 作者: rapoo

求一正则,写了好久没有成功
<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(过客)的方法不错,帮你测试了!

读书人网 >asp.net

热点推荐