Skip to content

Instantly share code, notes, and snippets.

@hartzis
Forked from irrationalistic/parseTweet.js
Created June 2, 2014 22:40
Show Gist options
  • Save hartzis/02a545fa6048a996b588 to your computer and use it in GitHub Desktop.
Save hartzis/02a545fa6048a996b588 to your computer and use it in GitHub Desktop.
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