.net 使用正则表达式将URL转换为锚定标记
我希望将以下不同的输入类型转换为以下锚定标记:.net 使用正则表达式将URL转换为锚定标记,.net,regex,vb.net,anchor,asp.net-2.0,.net,Regex,Vb.net,Anchor,Asp.net 2.0,我希望将以下不同的输入类型转换为以下锚定标记: http://www.stackoverflow.com https://www.stackoverflow.com www.stackoverflow.com 替换为: <a href='http(s)://www.stackoverflow.com' title='Link opens in new window' target='_blank'>www.stackoverflow.com</a>
http://www.stackoverflow.com
https://www.stackoverflow.com
www.stackoverflow.com
替换为:
<a href='http(s)://www.stackoverflow.com' title='Link opens in new window' target='_blank'>www.stackoverflow.com</a>
我想我自己也可以写一些类似的东西,但我想知道是否有一个标准的脚本已经过全面的测试
非常感谢 找到此函数:
Public Shared Function ConvertUrlsToLinks(ByVal msg As String) As String
Dim regex As String = "((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])"
Dim r As New Regex(regex, RegexOptions.IgnoreCase)
Return r.Replace(msg, "<a href=""$1"" title=""Click to open in a new window or tab"" target=""_blank"">$1</a>").Replace("href=""www", "href=""http://www")
End Function
公共共享函数ConvertUrlsToLinks(ByVal msg作为字符串)作为字符串
Dim regex As String=“((www.|(http | https | ftp | news | file)+\:\/)[_;.a-z0-9-]+\.[a-z0-9\/_;:@=.+?,#%&-*[^.| \'.| \'.ん!(|?,|>|