Patrick Gates
Patrick Gates

Reputation: 391

twitter regular expressions

I need 3 different regular expressions

if returning just the username and also being true isn't possible with one regex, then I could use one to match to, and one that will delete the 'D' or the '@' or the 'RT', thank you

(fyi, i'm using AS3 to do this)

Upvotes: 1

Views: 591

Answers (2)

Yozef
Yozef

Reputation: 829

public function convertTwitterMsg (o:Object):void {
   trace('New Tweet: ' + o);
   var original:String = o.title;
   _tweet = original.replace(/(^|\s)@(\w+)/g, "$1@<a href=\"http://www.twitter.com/$2\">$2</a>");
   _final = _tweet.replace(/(^|\s)#(\w+)/g, "$1#<a href=\"http://search.twitter.com/search?q=%23$2\">$2</a>");
   ta.htmlText = _final;
}

ta should be the id of your mx:TextArea, you could also use spark, but it changed the way you style your text in spark. _tweet is a String

I copied pasted the function, use at your own convenience.

Upvotes: 0

dawg
dawg

Reputation: 104092

  1. D patrickgates use ^D (\w+) to capture 'patrickgates'
  2. @patrickgates hello, world use ^@(\w+) to capture 'patrickgates'
  3. RT @patrickgates use `^RT @(\w+) to capture 'patrickgates'

If you want a single regex to capture patrickgates from all three of your examples:

^(?:D |@|RT @)(\w+)

Upvotes: 3

Related Questions