解析HTML文档?

时间:2010-07-08 11:47:34

标签: c#

如何替换保存在数据库中的图像源,html文本?

谢谢

2 个答案:

答案 0 :(得分:4)

您应该尝试HTML Agility Pack

答案 1 :(得分:0)

http://social.msdn.microsoft.com/Forums/en-US/regexp/thread/37f46a25-113c-420d-aab8-eea98d341189

string s = "<img src='1.jpg'><img src='2.jpg'><img src='3.jpg'><img src='4.jpg'>";
string pattern = @"<img\s+src\s*=\s*["']([^"']+)["']\s*/*>";
string output = string.Empty;
output = Regex.Replace(s, pattern, "[Image: $1]");

Regex to get src value from an img tag