public static string GetFirstImages(string htmlText)
{
const string pattern = "<img [^~]*?>";
const string pattern1 = "src\\s*=\\s*((\"|\')?)(?<url>\\S+)(\"|\')?[^>]*";
string s = null;
Match match = Regex.Match(htmlText, pattern, RegexOptions.IgnoreCase); //找到img标记
if (match.Success)
{
string img = match.Value;
string imgsrc = Regex.Match(img, pattern1, RegexOptions.IgnoreCase).Result("${url}");
imgsrc = Regex.Replace(imgsrc, "\"|\'|\\>", "", RegexOptions.IgnoreCase);
s = imgsrc;
}
return s;
}
来源 http://topic.csdn.net/u/20100612/13/27e2b00b-146f-41df-8962-7a0693148fff.html