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

正则式求解图片的超级链接地址,在线散分。该怎么解决

2012-02-15 
正则式求解图片的超级链接地址,在线散分。。撒旦非飞鸽 Centerimgsrchttp://img1.qq.com/news/20060117/

正则式求解图片的超级链接地址,在线散分。。
撒旦非飞鸽 <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;
}

热点排行