tryusing System.Text.RegularExpressions;string s = "................."; Regex re = new Regex(@"<img[^>]+src=(?:""(?<src>[^""]+)""|'(?<src>[^']+)'|(?<src>\S+))[^>]*>", RegexOptions.IgnoreCase);
MatchCollection mc = re.Matches(s);
Console.WriteLine(mc.Count);
foreach(Match m in mc)
Console.WriteLine("{0} --> {1}", m.Value, m.Groups["src"].Value);

解决方案 »

  1.   

    saucer(思归/MVP) 你的正则表达式,好像也不能完全将html 中的 <img> 标签全部找出来,还有一些其他的东西在里面,例如: width 和 heigh 的属性值。我的表达式在一些网页中可以将<img>标签的找出来,但有些网页却还存在其他的<tb>之类的标签。
    <img\s*src\s*=\s*[""']?.+\s*.(gif|jpg|bmp|tif|png)\s*.+[^\w]
    请问应该如何改?
      

  2.   

    sorry saucer(思归/MVP) 看错了,基本上能匹配得上,但是像www.microsoft.com 这样的网站,他在<img src=....> 后面加入了一些script 的代码,单单是用您的表达式还不能完完全的匹配出来。
      

  3.   

    sure, since they are not <img> tags, they are generating imgs inside javascript, this kind of matching is very page specific, no general pattern available