The problem with your regexp is that +
is a special character, meaning "repeat the previous character one or more times", in your case, it would match g
one time, and then the (.*?)
would match the literal +
.
The solution is to escape the +
by preceding it with a \
:
>>> email = 'something+company@gmail.com'
>>> re.findall(r'something\+(.*?)@', email)
['company']
Having said that, you don't really need a regular expression here.
Your goal is to get all text between the first +
and the first @
, which you can do with:
>>> email = 'something+company@gmail.com'
>>> email[email.find('+')+1:email.find('@')]
'company'
Note that this code will give unexpected results if there's no +
or @
, so you'll probably want to add a check around this (e.g. if '+' in email: ...
).
In addition, you can actually have quoted @
s and such in emails, so this is not 100% RFC-compliant. However, last time I checked many MTAs and email clients don't support that anyway, so it's not really something you need to worry about as such.