Skip to content

Instantly share code, notes, and snippets.

@aramk
Created November 24, 2012 04:58
Show Gist options
  • Save aramk/4138482 to your computer and use it in GitHub Desktop.
Save aramk/4138482 to your computer and use it in GitHub Desktop.
Creates a link out a url string
String.prototype.linkify = function(target) {
target = typeof target != 'undefined' ? target : '';
return this.replace(/(http(s)?:\/\/(\S)+)/gmi, '<a href="$1" target="' + target + '">$1</a>');
};
"http://www.google.com".linkify() // "<a href="http://www.google.com" target="">http://www.google.com</a>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment