Skip to content

Instantly share code, notes, and snippets.

@TastyToast
Created September 9, 2013 23:50
Show Gist options
  • Save TastyToast/6503103 to your computer and use it in GitHub Desktop.
Save TastyToast/6503103 to your computer and use it in GitHub Desktop.
Change links to urls
function urlify(text){
var urlRegex = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi;
return text.replace(urlRegex, function(url){
return '<a href="' + url + '">' + url + '</a>';
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment