views:

33

answers:

1

I need 3 different regular expressions

  • one that finds at the beginning of the string a 'D' and a space then a name, so 'D patrickgates hello there' would return 'D patrickgates', or if all possible would return just 'patrickgates'
  • one that will find the @ sign and a name together anywhere in the string so '@patrickgates hello, world' would work and return '@patrickgates' or if at all possible would return just 'patrickgates'
  • one that will find 'RT' and a space and then '@' and the username at the beginning of the string so 'RT @patrickgates' would work

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)

+2  A: 
  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+)

drewk
thank you so much
Patrick Gates
'soright... Thanks for the "check"
drewk