直接上方法
public static ArrayList getImgUrl(string html, string regstr, string keyname) { ArrayList resultStr = new ArrayList(); Regex r = new Regex(regstr, RegexOptions.IgnoreCase); MatchCollection mc = r.Matches(html); foreach (Match m in mc) { resultStr.Add(m.Groups[keyname].Value.ToLower()); } if (resultStr.Count > 0) { return resultStr; } else { //没有地址的时候返回空字符 resultStr.Add(""); return resultStr; } }
调用
var imgs=getImgUrl(pro.Description, @"<IMG[^>]+src=s*(?:'(?<src>[^']+)'|""(?<src>[^""]+)""|(?<src>[^>s]+))s*[^>]*>", "src");