Regular Expression to convert URL to Hyperlink

Regular Expression to convert URL to Hyperlink

The following method will turn all urls in the input parameter string sInput into
HTML hyperlinks. Please take a moment to rate this Tip:

http://www.turnkeytools.com/polls/default.asp?POLLID=10000080&DOMAINID=4610

using System.Text.RegularExpressions;


public string ConvertURLsToHyperlinks(string sInput)
{
return Regex.Replace(sInput, @"(\bhttp://[^ ]+\b)", @"<a href=""$0"">$0</a>");
}


Submission Date:  3/18/2003 8:34:14 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (720 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP