Link to home
Start Free TrialLog in
Avatar of tuthlis
tuthlis

asked on

Regex for hyperlinking URLs & e-mail addresses

I've got bits and pieces of text flowing through a program into a database for display on the web only.  Some of these bits and pieces may contain web site URLs (almost never beginning with http://, but www instead) and e-mail addresses.  I'd like to be able to identify and wrap up those pieces in <a> tags (i.e. <a href="[URL]"> and <a href="mailto:[EMail]">), much like this question is hyperlinked in certain places.

I could hobble my way through regular expressions (I'm a .NET regex newbie) but I was curious if the experts out there had a couple of regular expressions along with code they already use for this purpose?  I found this one while searching around:
(?<url>http://(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&=]*)?)
 but I don't completely understand what it does and I want to know if there's one that's tried and tested and true for both web site URLs and e-mail addresses.  Or if someone out there has a better method not using Regular Expressions, I'd love to know what is also.  

Thanks for your time.
ASKER CERTIFIED SOLUTION
Avatar of ayrezyle
ayrezyle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial