Skip to content

Instantly share code, notes, and snippets.

@DmitryBaranovskiy
Created June 16, 2010 01:21
Show Gist options
  • Save DmitryBaranovskiy/439983 to your computer and use it in GitHub Desktop.
Save DmitryBaranovskiy/439983 to your computer and use it in GitHub Desktop.
var text = "Tweet…"
text.replace(/(^|\s)(?:#([\d\w_]+)|@([\d\w_]{1,15}))|(https?:\/\/[^\s"]+[\d\w_\-\/])|([^\s:@"]+@[^\s:@"]*)/gi, function(all, space, hashtag, username, link, email) {
var res = '<a href="mailto:' + email + '">' + email + "</a>";
hashtag && (res = space + '<a href="http://search.twitter.com/search?q=%23' + hashtag + '">#' + hashtag + "</a>");
username && (res = space + '<a href="http://twitter.com/' + username + '">@' + username + "</a>");
link && (res = '<a href="' + encodeURI(decodeURI(link.replace(/<[^>]*>/g, ""))) + '">' + link + "</a>");
return res;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment