I have a tweet text like this:
"@user1 @user2 blablabla @user3"
I want to use a regex to filter the users in the beginning of a tweet. That would mean @user1 and @user2. There are not always the same number of users, there might be one, two, three…
I’m trying this with re.IGNORECASE:
re.compile(ur'^(@[a-z0-9_]*\s)*')
But doesn’t match what I want, I’ve tried everything I’ve come up with, but failed. I’m not very familiar with Python regex, but this how I would do it with egrep:
echo "@user1 @user2 blablabla @user3" | egrep '^(@[[:alnum:]_]*[ ]*)*'
Thanks
Editing
The regex was right, I was just checking the solution the wrong way.
tweet = "@user1 @user2 blablabla @user3"
re.compile(ur'^(@[a-z0-9_]*\s)*').match(tweet).groups()
Instead of:
re.compile(ur'^(@[a-z0-9_]*\s)*').match(tweet).group(0)
Clearer version of the regex:
re.compile(ur'^(@\w+\s)+').match(tweet).group(0)
Try this regular expression:
^(@\w+\s)+.In
@user1 @user2 blablabla @user3it will match: