<img src="https://ab.cctv.com/img/6eKv0uVZFelwVRyZ39YCdtVBtuM3Y5Fn_wpPCNEStwxIyINeGhYOuOsjJoFFoZyW16JwpyBhyAup.jpg" width="290" height="80" alt="my photo" border="0">如何把src后的图片地址给匹配了?

解决方案 »

  1.   

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

  2.   

    6eKv0uVZFelwVRyZ39YCdtVBtuM3Y5Fn_wpPCNEStwxIyINeGhYOuOsjJoFFoZyW16JwpyBhyAup.jpg我就要这个
      

  3.   

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

  4.   

    <img[^>]*src\s?=\s?(['""])?[^'""\s>]*?(?<img>[^'""\s>/]*)\1[^>]*>
      

  5.   

    @"<img[^>]*src=(['""])?[^'""\s>]*?(?<img>[^'""\s>/]*)\1[^>]*>", 
    这个地方是不是效率不高啊?
    [^>]*
    贪婪搜索,先搜索到>表示匹配失败,然后返回来看src...这些,然后选择的让出自己匹配。为什么不用.*?呢
      

  6.   

    @"<img[^>]*(\\s+)src(\\s*)=(\\s*)(?<quo>(\"|')?)([^>/]+/)+(?<img>[^/]+)\\k<quo>[^>]*>",