I want the following different input types to be开发者_Go百科 converted into the following anchor tag:
http://www.stackoverflow.com
https://www.stackoverflow.com
www.stackoverflow.com
Replaced with:
<a href='http(s)://www.stackoverflow.com' title='Link opens in new window' target='_blank'>www.stackoverflow.com</a>
I think I could probably write something similar myself, but I'd like to know if there is a standard script for doing this which has been throughly tested?
Many Thanks!
Found this function:
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
精彩评论