获取网页中图片链接的路径的正则表达式
private static Regex RegImgSrc = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
/// <summary>
/// 获取图片的链接路径,返回数组集合值
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ReplaceImgSrc(string str)
{
MatchCollection mc;
Base64String baseto64 = new Base64String();
mc = RegImgSrc.Matches(str);
// 取得匹配项列表
foreach (Match match in mc)
{
str = str.Replace(
match.Groups["imgUrl"].Value
, "data:image/png;base64," + baseto64.ConvertToBase64String(match.Groups["imgUrl"].Value));
}
return str;
}
#endregion