Skip to content

Instantly share code, notes, and snippets.

@ghostrocket
Created December 31, 2010 16:54
Show Gist options
  • Save ghostrocket/761147 to your computer and use it in GitHub Desktop.
Save ghostrocket/761147 to your computer and use it in GitHub Desktop.
Linkify Tweet in Javascript
String.prototype.linkify_tweet = function() {
var tweet = this.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,"<a href='$1'>$1</a>");
tweet = tweet.replace(/(^|\s)@(\w+)/g, "$1<a href=\"http://www.twitter.com/$2\">@$2</a>");
return tweet.replace(/(^|\s)#(\w+)/g, "$1<a href=\"http://search.twitter.com/search?q=%23$2\">#$2</a>");
};
@ghostrocket
Copy link
Author

links tweet to @replies, #hashtags, and http://someurl.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment