Discuss / Python / regular expression

regular expression

Topic source

叫我_小军

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

import re --版本一-- re1_email = re.compile(r'^[\w.]+@[\w.]+[\w.]+$') print(re1_email.match('someone@gmail.com')) print(re1_email.match('bill.gates@microsoft.com'))

--版本二-- re2_email = re.compile(r'^<([\w\s]*)>\s[\w.]+@[\w.]+[\w.]+$') name = re2_email.match('<Tom Paris> tom@voyager.org').groups() print(name)

源码有问题,差一对(),改了一下就行了 re2_email = re.compile(r'^<([\w\s]*)>\s+([\w.]+@[\w.]+[\w.]+)$')


  • 1

Reply