I have hash:
{'login': u'myemail ([email protected])'}
I need parse only email [email protected]
What regexp I must compose
I have hash:
{'login': u'myemail ([email protected])'}
I need parse only email [email protected]
What regexp I must compose
No regex is needed. Use string manipulation instead. This will split the value on the first space, then strip the () from the second item ([1]) of the returned array.
yourhash = {'login': u'myemail ([email protected])'}
email = yourhash['login'].split()[1].strip("()")
print(email)
# [email protected]
If you really need a regular expression solution (versus the excellent string split options also posted) this will do it for you:
>>> import re
>>> re.match('.*\((.*)\)', 'myemail ([email protected])').group(1)
'[email protected]'
>>>
There are many patterns for matching emails. A good resource can be found here.
For example,
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$