我正在尝试从a标签中提取URL,但是我得到的不是https://website.com/-id1,而是a标签的文本链接。以下是我的代码:
string text="<a style=\"font - weight: bold; \" href=\"https://website.com/-id1\">MyLink</a>";
string parsed = Regex.Replace(text, " <[^>] + href =\"([^\"]+)\"[^>]*>", "$1 " );
parsed = Regex.Replace(parsed, "<[^>]+>", "");
Console.WriteLine(parsed);
我得到的结果是MyLink,但这并不是我想要的。我需要类似于以下内容:
https://website.com/-id1
任何帮助或链接将不胜感激。
.Match
来捕获URL,而不是试图删除URL之外的任何内容。例如:.Match(text,""href\\s*=\\s*\".*?\"")
。 - Panagiotis Kanavos