c#定义正则表达式用来匹配img标签

发布日期:2018-02-05    浏览次数:1085
 public static string[] GetImgs(string html)
        {   // 定义正则表达式用来匹配 img 标签            
            Regex regImg = new Regex(@"]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
            // 搜索匹配的字符串
            MatchCollection matches = regImg.Matches(html);
            int i = 0;
            string[] imgs = new string[matches.Count];
            // 取得匹配项列表 
            foreach (Match match in matches)
            {
                imgs[i++] = match.Groups["imgUrl"].Value;
            }
            return imgs;
        }

本文网址:https://www.wyxxw.cn/blog-detail-2-6-58.html

返回列表

非特殊说明,本文版权归原作者所有,转载请注明出处

提示:本站所有资源仅供学习与参考,请勿用于商业用途。图片来自互联网~如侵犯您的权益,请联系QQ:1067507709.

提示:转载请注明来自:https://www.wyxxw.cn/blog-detail-2-6-58.html 。 本文发布者:momo