import re regex = r'^(<\w[\s\w]+>\s)?(\w+[\w+.]*@\w+.(org|com)$)' # 题目一:正则匹配 m = re.compile(regex) # 纯Email地址 if m.match('someone@gmail.com'): print('match someone@gmail.com') if m.match('bill.gates@microsoft.com'): print('match bill.gates@microsoft.com') # 带名字的Email地址 if m.match('<Tom Paris> tom@voyager.org'): print('match <Tom Paris> tom@voyager.org') # 题目二:提取带名字的Email地址 m_email = m.match('<Tom Paris> tom@voyager.org').group(2) print(m_email)
详解请关注我的CSDN博客: http://blog.csdn.net/sunflowerduidui/article/details/51489394
我试了一下,不管是''还是r''里面如果不是.而是.的话,就表示的是任意字符,而不是小数点的意思。把.com换成;com也满足
Sign in to make a reply
南海的椰子
详解请关注我的CSDN博客: http://blog.csdn.net/sunflowerduidui/article/details/51489394