Skip to content

Instantly share code, notes, and snippets.

@matthewford
Created May 18, 2009 11:57
Show Gist options
  • Save matthewford/113431 to your computer and use it in GitHub Desktop.
Save matthewford/113431 to your computer and use it in GitHub Desktop.
function linkify(s) {
var entities = {
'"' : '"',
'&' : '&',
'<' : '&lt;',
'>' : '&gt;'
};
return s.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m) {
return m.link(m);
}).replace(/(^|[^\w])(@[\d\w\-]+)/g, function(d, m1, m2) {
return m1 + '@<a href="http://twitter.com/' + m2.substr(1) + '">' + m2.substr(1) + '</a>';
}).replace(/"&<>/, function (m) {
return entities[m];
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment