Discuss / Python / Daily Work

Daily Work

Topic source

无愠无殇

#1 Created at ... [Delete] [Delete and Lock User]
__author__ = 'Yuriy'

import re

reg = r'^(<[\w\s]+>)?\s*[\w\.]+@[\w]+\.[\w]+$'

s1 = 'someone@gmail.com'
s2 = 'bill.gates@microsoft.com'
s3 = '<Tom Paris> tom@voyager.org'
m = re.compile(reg)

print(m.match(s1).group(0))

print(m.match(s2).group(0))

print(m.match(s3).group(0))

# D:\python34\python.exe "D:/PyCharm 4.0.4/Code/demo5.py"
# someone@gmail.com
# bill.gates@microsoft.com
# <Tom Paris> tom@voyager.org

  • 1

Reply