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

正则式求解图片的超级链接地址,在线散分。。
撒旦非飞鸽 <Center> <img   src=http://img1.qq.com/news/20060117/3037556.jpg> 撒旦非个 <br> <br>   暗示疗法空间

如何通过正则式过滤出图片的超级链接地址(图片格式可为.jpg   .jpeg   .gif   .bmp   .png)     http://img1.qq.com/news/20060117/3037556.jpg   字符串;

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

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

上面是取第一个 <img...> 标签内的图片地址,如果是取无论是否在标签内的,只要是上述扩展名的图片地址,这样

string result = " ";
Match m = Regex.Match(yourStr, @ "http://[^\s]*\.(jpg|jpeg|gif|bmp|png) ", RegexOptions.IgnoreCase);
if (m.Success)
{
result = m.Value;
}