Detecting URLs within a string PHP and Javascript – Mr. Joel Kemp

Screen Shot 2013 03 20 At 1.59.53 Pm

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:

 

Including subpaths: