I’m trying to convert text containing URL’s into HTML anchors using Visual Basic in ASP.NET 2.0, so far I have this (which is working) but it only picks up http and https:
Regex.Replace(message, "https?://[^\s]*", "<a href=""$0"">$0</a>", RegexOptions.IgnoreCase)
I would like it to be able to also pick up anything starting “www.”, so I tried the following:
Regex.Replace(message, "(https?://|www\.)[^\s]*", "<a href=""$0"">$0</a>", RegexOptions.IgnoreCase)
However, if it starts with “www.” the first $0 in the replacement requires an additional “http://” to be put in front… and I haven’t got a clue how to do it (or if it’s possible).
Try this: