I have the following example tweet:
RT @user1: who are @thing and @user2?
I only want to have user1, thing and user2.
What regular expression can I use to extract those three names?
PS: A username must only contain letters, numbers and underscores.
This should do it (I used named captures for convenience):
.+?@(?[a-zA-Z0-9_]+):[^@]+?@(?[^\s]+)[^@]+?@(?[a-zA-Z0-9_]+)
Tested:
In Ruby (irb):
In Python:
In PHP:
Is a good idea include twitter text library [1] in your project to resolve this text issues.
[1] https://github.com/twitter/twitter-text-js
The above covers the following scenario, which other answers in this thread do not:
try an iterator (findall) with this regex:
bye