【发布时间】:2019-02-27 02:26:54
【问题描述】:
我正在尝试用锚标记替换所有出现的 URL。
我可以对大多数 URL 字符执行此操作,但是当 URL 中有 ( 和 ) 时,代码会中断。
例如。
https://example.com/Heavy-Industry/Global-Perfluorosulfonic-Acid-(PFSA)-Market-Status-By-Manufacturers,-Types-And-Application,-History-And-Forecast-2025#sample
这是我的代码:
protected string MakeLink(string text)
{
string text2 = Regex.Replace(text,
@"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)",
"<a target='_blank' href='$1'>$1</a>");
return text2;
}
【问题讨论】: