正则表达式读取图片地址

using System.Text.RegularExpressions;

 

    protected string GetImgUrl(string img) {
        Regex  regex  =  new  Regex(@"<img.*src=[/""|/']?([^/""]*)[/'|/""]?[^/]*[/]?>",  RegexOptions.Compiled  |  RegexOptions.IgnoreCase  );
        string str = "";
        foreach (Match matchItem in regex.Matches(img)) 
        {
            if (matchItem.Groups[1] != null)
            {
                str += matchItem.Groups[1].Value;
            } 
        }
        return str;
    }

你可能感兴趣的:(正则表达式,String,null,regex)