Discuss / Python / 作业

作业

Topic source

北卡上校

#1 Created at ... [Delete] [Delete and Lock User]
import re

test1 = 'someone@gmail.com'
test2 = 'bill.gates@microsoft.com'
test3 = 'ssdg_wfef@nbbjk.cn'
test4 = '<Tom Paris> tom@voyager.org'
mails=[test1, test2, test3, test4]
re_email = re.compile(r'^(<[A-Za-z]+.?[A-Za-z]+>)?.+(\w+\W?\w+)@(\w)+\.(\w){2,5}$')

for mail in mails:
    m = re_email.match(mail)
    print(m.group(1), m.group(0) if m else 'No match')
(None, 'someone@gmail.com')
(None, 'bill.gates@microsoft.com')
(None, 'ssdg_wfef@nbbjk.cn')
('<Tom Paris>', '<Tom Paris> tom@voyager.org')
[Finished in 0.076s]

  • 1

Reply