【发布时间】:2014-08-25 17:51:50
【问题描述】:
Regex linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string rawString = link;
foreach (Match m in linkParser.Matches(rawString))
{
string links = m.Value;
}
我试图从这个字符串中解析/获取链接:
<a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=112190&forum=scoops1"><b>
我只想得到这部分:
http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=112190&forum=scoops1
但我在字符串链接中得到的是:
http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=112190&forum=scoops1"><b
最后剩下的是>
【问题讨论】:
-
在锚点中还是从文本中?如果是前者
<a href=\"((http|https)://.*?)\">或者使用像 Html Agility Pack 这样的 Protper 解析器 -
请检查这个answer 到另一个类似的问题。
-
请不要一次又一次地重新发布相同的问题,最好编辑您的old question 并在确实需要时重新打开它,但至于您的其他问题,最佳解决方案是
NOT TO USE REGEX但更多合适的工具比如HTML Agility Pack,只是因为HTML is no regular language