Created
May 29, 2014 20:55
-
-
Save irrationalistic/744b2a6958e03b23539c to your computer and use it in GitHub Desktop.
Parse Tweets - Simple
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
var parseTweet = function(tweetText) { | |
var reghash, reguri, regusername; | |
reguri = /(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*))/g; | |
regusername = /([@]+([A-Za-z0-9-_]+))/g; | |
reghash = /[#]+([A-Za-z0-9-_]+)/g; | |
tweetText = tweetText.replace(reguri, "<a href='$1' target='_blank'>$1</a>"); | |
tweetText = tweetText.replace(regusername, "<a href='http://twitter.com/$2' target='_blank'>$1</a>"); | |
tweetText = tweetText.replace(reghash, "<a href='http://twitter.com/search?q=%23$1' target='_blank'>#$1</a>"); | |
return tweetText; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment