Skip to content

Instantly share code, notes, and snippets.

@thameera
Forked from ghostrocket/tweet-linkify.js
Last active December 28, 2015 12:39
Show Gist options
  • Save thameera/7502546 to your computer and use it in GitHub Desktop.
Save thameera/7502546 to your computer and use it in GitHub Desktop.
Linkify the text of a tweet
var linkify_tweet = function(tweet) {
tweet = tweet.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