Created
December 31, 2010 16:54
-
-
Save ghostrocket/761147 to your computer and use it in GitHub Desktop.
Linkify Tweet in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
links tweet to @replies, #hashtags, and http://someurl.com