Created
November 4, 2011 15:46
-
-
Save joshuabaker/1339648 to your computer and use it in GitHub Desktop.
Parse Tweet
This file contains hidden or 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
function parseTweet(str) { | |
return str | |
.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi, '<a href="$1" target="_blank" class="tweet-link">$1</a>') | |
.replace(/(^|[\W])@(\w+)/gi, '$1@<a href="http://twitter.com/$2">$2</a>') | |
.replace(/\#([a-zA-Z0-9-_]+)/gi, '<a href="http://twitter.com/search/%23$1" target="_blank" class="tweet-hash">#$1</a>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method should be considered deprecated. The use of Twitter entities is encouraged.