Posted By

kuril on 02/05/11


Tagged

regexp parser twitter


Versions (?)

Twitter links parser


 / Published in: ActionScript
 

  1. public static const homeLink:String = "http://twitter.com";
  2. public static const timelineURIPattern:String = homeLink + "/statuses/user_timeline/{userName}.xml?count={count}&page={page}";
  3. public static const userHomeURIPattern:String = homeLink + "/{userName}";
  4.  
  5.  
  6. public static const linkPattern:RegExp = /https?:\/\/([-\w\.]+)+(\/([\w\/_\.]*(\?\S+)?(#\S+)?)?)?/g;
  7. public static const linkReplace:String = "<a href='$&' target='_blank'>$&</a>";
  8. public static const userPattern:RegExp = /@(\w+)/g;
  9. public static const userReplace:String = "@<a href='"+ homeLink + "/$1' target='_blank'>$1</a>";
  10.  
  11. public static const tagLink:String = "http://search.twitter.com/search?q=%23";
  12. public static const tagPattern:RegExp = /(\s+)#(\w+)/g;
  13. public static const tagReplace:String = "$1<a href='"+tagLink+"$2' target='_blank'>#$2</a>";
  14. public static const tagPattern2:RegExp = /^#(\w+)/;
  15. public static const tagReplace2:String = "<a href='"+tagLink+"$1' target='_blank'>#$1</a>";
  16.  
  17.  
  18. public static function replaceAll(text:String):String
  19. {
  20. text = text.replace(linkPattern,linkReplace);
  21. text = text.replace(userPattern,userReplace);
  22. text = text.replace(tagPattern,tagReplace);
  23. text = text.replace(tagPattern2,tagReplace2);
  24. return text;
  25. }
  26.  

Report this snippet  

You need to login to post a comment.