Skip to content

Instantly share code, notes, and snippets.

@moskinson
Last active December 16, 2015 12:38
Show Gist options
  • Select an option

  • Save moskinson/5435376 to your computer and use it in GitHub Desktop.

Select an option

Save moskinson/5435376 to your computer and use it in GitHub Desktop.
Url regex JavaScript and add a href tag
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