日期:2014-05-19  浏览次数:20785 次

求个正则表达式。高手进!
<img   src= "https://ab.cctv.com/img/6eKv0uVZFelwVRyZ39YCdtVBtuM3Y5Fn_wpPCNEStwxIyINeGhYOuOsjJoFFoZyW16JwpyBhyAup.jpg "   width= "290 "   height= "80 "   alt= "my   photo "   border= "0 ">

如何把src后的图片地址给匹配了?

------解决方案--------------------
try

string yourStr = ....................;
Match m = Regex.Match(yourStr, @ " <img[^> ]*src=([ ' " "])?(? <img> [^ ' " "\s> ]*)\1[^> ]*> ", RegexOptions.IgnoreCase);
if (m.Success)
{
MessageBox.Show(m.Groups[ "img "].Value);
}

------解决方案--------------------
<img[^> ]*src\s?=\s?([ ' " "])?[^ ' " "\s> ]*?(? <img> [^ ' " "\s> /]*)\1[^> ]*>
------解决方案--------------------
@ " <img[^> ]*src=([ ' " "])?[^ ' " "\s> ]*?(? <img> [^ ' " "\s> /]*)\1[^> ]*> ",
这个地方是不是效率不高啊?
[^> ]*
贪婪搜索,先搜索到> 表示匹配失败,然后返回来看src...这些,然后选择的让出自己匹配。为什么不用.*?呢
------解决方案--------------------
@ " <img[^> ]*(\\s+)src(\\s*)=(\\s*)(? <quo> (\ "| ')?)([^> /]+/)+(? <img> [^/]+)\\k <quo> [^> ]*> ",
------解决方案--------------------
前面那个 @不应该有的 ,贴了别人的忘记删掉了,哈