我有一个字符串,其中应包含表单中的项目列表,{0}、{1} 和 {2} 是字符串,我基本上想提取它们。
我确实想针对 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 解析器来执行此操作?
最佳答案
使用 HTML 敏捷包库解析 HTML,可以找到 here
关于c# - 在c#中捕获链接的rel类型和href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1014534/