Detecting URLs within a string PHP and Javascript

I had to roll my own regex solution for translating embedded links within text to clickable html links. Stuff on the web had too many false positives. Hope it helps!

Javascript:

/(((http(s?)(:\/\/))?([w]{3}\.)?)([a-z|0-9])+\.(com(\.au)?|org|me|net|ly|be|gl|info|(co(\.))?uk|ca|nz|tv)(\/[^\s]+)*)+/g

PHP:

"/(((http(s?)(:\/\/))?([w]{3}\.)?)([a-z|0-9])+\.(com(\.au)?|org|me|net|ly|be|gl|info|(co(\.))?uk|ca|nz|tv)((\/[^\s]+)*)+)/"

Properly detects the urls in the following formats:

Screen Shot 2013-03-20 at 1.59.53 PM

Including subpaths:

Screen Shot 2013-04-08 at 1.37.11 PM

Comments

comments