我有一个字符串应该包含表单中的项目列表{0},{1}和{2}是字符串,我想基本上提取它们。在c中捕获链接的rel类型和href#
我确实希望这样做的一部分的HTML解析问题,我听说用正则表达式解析HTML是不好的。 (像here)
我甚至不知道如何用正则表达式来做到这一点。
这是据我得到
string format = "<link rel=\".*\" type=\".*\" href=\".*\">";
Regex reg = new Regex(format);
MatchCollection matches = reg.Matches(input, 0);
foreach (Match match in matches)
{
string rel = string.Empty;
string type = string.Empty;
string href = string.Empty;
//not sure what to do here to get these values for each from the match
}
我的研究转向了以前,我可能完全使用正则表达式在错误的轨道上。
你会如何用我选择的方法或HTML解析器来做到这一点?
谢谢。我给你的复选标记是因为你的答案有帮助的代码,并且你解释了为什么要使用解析器而不是正则表达式。 感谢Rony为HTML链接提供的链接,我刚下载了它。 – 2009-06-18 19:29:51