展开全部
给你个函数
public static string GetContentImgUrl(string content)
{
string imgUrl = "";
Regex imgUrlReg = new Regex(@"<img\s+.*?>", RegexOptions.IgnoreCase);
MatchCollection mc = imgUrlReg.Matches(content);
int i = 0;
foreach (Match m in mc)
{
if (i == 0)
{
imgUrl = m.ToString();
}
i++;
}
Regex reg = new Regex("src=[\"|'|\\s*].*?[\"|'|\\s+]", RegexOptions.IgnoreCase);
imgUrl = reg.Match(imgUrl).ToString();
Regex srcReg = new Regex("src=", RegexOptions.IgnoreCase);
imgUrl = srcReg.Replace(imgUrl, "").ToString();
imgUrl = imgUrl.Replace("'", "");
imgUrl = imgUrl.Replace("\"", "");
return imgUrl;
}
public static string GetContentImgUrl(string content)
{
string imgUrl = "";
Regex imgUrlReg = new Regex(@"<img\s+.*?>", RegexOptions.IgnoreCase);
MatchCollection mc = imgUrlReg.Matches(content);
int i = 0;
foreach (Match m in mc)
{
if (i == 0)
{
imgUrl = m.ToString();
}
i++;
}
Regex reg = new Regex("src=[\"|'|\\s*].*?[\"|'|\\s+]", RegexOptions.IgnoreCase);
imgUrl = reg.Match(imgUrl).ToString();
Regex srcReg = new Regex("src=", RegexOptions.IgnoreCase);
imgUrl = srcReg.Replace(imgUrl, "").ToString();
imgUrl = imgUrl.Replace("'", "");
imgUrl = imgUrl.Replace("\"", "");
return imgUrl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询