Skip to content

Instantly share code, notes, and snippets.

@marcinkuzminski
Last active September 26, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcinkuzminski/1104278 to your computer and use it in GitHub Desktop.
Save marcinkuzminski/1104278 to your computer and use it in GitHub Desktop.
JS: Replaces found url patterns in text to a clickable link
/**
* Replaces found url patterns in text
* to a clickable link
*/
function URL2Link(text) {
var pat = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(pat,"<a href='$1'>$1</a>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment