教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 asp.net 正则表达式匹配图片路径的实现代码

asp.net 正则表达式匹配图片路径的实现代码

发布时间:2016-05-11   编辑:jiaochengji.com
本文介绍下,在asp.net编程中用正则表达式,匹配网页中的图片路径的一例代码,有需要的朋友,参考下吧。

代码如下:
 

复制代码 代码示例:

//正则表达匹配图片路径
public static string[] GetHtmlImageUrlList(string sHtmlText)
{
     // 定义正则表达式用来匹配 img 标签
     Regex regImg = new Regex(@"<img/b[^<>]*?/bsrc[/s/t/r/n]*=[/s/t/r/n]*[""']?[/s/t/r/n]*(?<imgUrl>[^/s/t/r/n""'<>]*)[^<>]*?/?[/s/t/r/n]*>", RegexOptions.IgnoreCase);

     // 搜索匹配的字符串
     MatchCollection matches = regImg.Matches(sHtmlText);

     int i = 0;
     string[] sUrlList = new string[matches.Count];

     // 取得匹配项列表
     foreach (Match match in matches)
         sUrlList[i++] = match.Groups["imgUrl"].Value;

     return sUrlList;
}

您可能感兴趣的文章:
asp.net 正则表达式匹配图片路径的实现代码
php匹配图片地址的代码一例
PHP正则取图片路径的例子
PHP正则匹配日期和时间(时间戳转换)的例子
php匹配任何网址的正则表达式
PHP正则匹配获取URL中域名的代码
php正则匹配重写html图片img路径的代码一例
php正则匹配图片路径的方法参考
常用正则表达式全集
php正则表达式完全教程(五)

关键词: 路径  正则表达式   
[关闭]
~ ~