Discuss / Python / 两种正则匹配

两种正则匹配

Topic source

-Otokaze-

#1 Created at ... [Delete] [Delete and Lock User]
import re
email1=re.compile(r'^(?:\w|\d)+?@(?:\w|\d)+?\.\w+$')
email2=re.compile(r'^(<.*?>)\s+(?:\w|\d)+?@(?:\w|\d)+?\.\w+$')
a=email1.match(r'someone@gmail.com').group()
b=email2.match(r'<Tom Paris> tom@voyager.org')
b_0=b.group()
b_name=b.group(1)
print(a)
print(b_0)
print(b_name)

  • 1

Reply