Last active
December 16, 2015 12:38
-
-
Save moskinson/5435376 to your computer and use it in GitHub Desktop.
Url regex JavaScript and add a href tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var urlregex = /([a-zA-Z0-9]+[.](aero|asia|biz|cat|com|coop|edu|es|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|xxx)[-a-zA-Z0-9+&@#\/%?=~_|:.,;]*)|((https?:\/\/)?([-a-zA-Z0-9_]+[.])*[-a-zA-Z0-9_]+[.][-a-zA-Z0-9_]+[.][a-zA-Z]+[a-zA-Z]+[-a-zA-Z0-9+&@#\/%?=~_|:.,;]*)|(\b(https?:\/\/)([-a-zA-Z0-9_]+[.])*[-a-zA-Z0-9_]+[.][a-zA-Z]+[a-zA-Z]+[-a-zA-Z0-9+&@#\/%?=~_|:.,;]*)/ig; | |
| return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment