Posted By

naren1012 on 02/25/11


Tagged

javascript


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

happynuclear
williamsww


Tweetify Plain Text


 / Published in: JavaScript
 

This is 3 lines of javascript code to tweetify plain text returned by Twitter API

Input : RT @TTintheCloud: How much are free #cloudcomputing trial offers from Google, Amazon and Microsoft actually WORTH? http://bit.ly/i4w4qa

Output : RT @TTintheCloud: How much are free #cloudcomputing trial offers from Google, Amazon and Microsoft actually WORTH? http://bit.ly/i4w4qa

  1. function tweetify(text) {
  2. text = text.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,
  3. "<a target=_blank href=$1>$1</a>");
  4. text = text.replace(/[\@]+([A-Za-z0-9-_]+)/gi, "<a target=_blank href=http://twitter.com/$1>@$1</a>");
  5. return text.replace(/(?:^| )[\#]+([A-Za-z0-9-_]+)/gi, " <a target=_blank href=http://search.twitter.com/search?q=&tag=$1&lang=all>#$1</a>");
  6. }

Report this snippet  

You need to login to post a comment.