111,098
社区成员




/// <summary>
/// 从HTML文本中获取所有图片路径
/// 相对路径或者网络图片http://
/// 要引用 using System.Text.RegularExpressions;
/// </summary>
/// <param name="source">来源内容</param>
/// <returns>图片路径列表</returns>
public static IList<string> getImageSrcArray(string source) {
IList<string> srcArr = new List<string>();
string strRegExPattern = @"<img[^>]+(src)\s*=\s*""?([^ "">]+)""?(?:[^>]+(width|height)\s*=\s*""?([^ "">]+)""?\s+(height|width)\s*=\s*""?([^ "">]+)""?)?(?:[^>]+(alt)\s*=\s*""?([^"">]+)""?)?";
Regex re = new Regex(strRegExPattern, RegexOptions.IgnoreCase);
Match m = re.Match(source);
while (m.Success) {
srcArr.Add(m.Groups[2].Value);
m = m.NextMatch();
}
return srcArr;
}