test
Topic sourceimport re
re_email = re.compile(r'^(<((\w+[ -_.]*)+)>)? {0,3}((\w+[-_.]*)+@(\w+[ -_.]+)+\w+)$')
while True:
r = input('plaues enter email address:').strip()
res = re.match(re_email, r)
if res:
if res.group(2) is not None:
print("email name: %s" % res.group(2).strip())
if res.group(5) is not None:
print("email address: %s" % res.group(4))
贴错了,重发
- 1
亦亦意意屹
import re
reemail = re.compile(r'^(<((\w+[ -.])+)>)? {0,3}((\w+[-_.])+@(\w+[ -_.]+)+\w+)$')
while True: r = input('plaues enter email address:').strip() res = re.match(re_email, r) if res: if res.group(2) is not None: print("email name: %s" % res.group(2).strip()) if res.group(5) is not None: print("email address: %s" % res.group(4))
测试通过如下 someone@gmail.com bill.gates@microsoft.com chrysan.xiao@pacn22-et.com.cn chrysan.xiao@pacn22--et.qq_im--123.ccom.cn chry--san.xiao@pacn22--et.com.cn
<Tom Paris-admin> tom@voyager.org
<Tom Paris-admin.cc> tom@voyager.org