Skip to content

Instantly share code, notes, and snippets.

@arbales
Created October 13, 2010 23:58
Show Gist options
  • Select an option

  • Save arbales/625235 to your computer and use it in GitHub Desktop.

Select an option

Save arbales/625235 to your computer and use it in GitHub Desktop.
function urlify(text) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url) {
return '<a href="' + url + '">' + url + '</a>';
})
// or alternatively
// return text.replace(urlRegex, '<a href="$1">$1</a>')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment