0

I have hash:

{'login': u'myemail ([email protected])'}

I need parse only email [email protected]

What regexp I must compose

4 Answers 4

2

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]
Sign up to request clarification or add additional context in comments.

Comments

2

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]'
>>>

Comments

1

Use string methods instead:

my_dict['login'].split['('][1].strip(')')

Comments

1

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}$

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.