python初学者,非常喜欢虫师的文章。
练习时发现一个小bug,http://www.VEVb.com/fnng/p/3782515.html
验证邮箱格式一题中,第三个x不允许有数字,但是测试发现abc@de.f2g 仍显示验证邮箱地址正确
发现 re.match() 匹配的只是开头,故想到了分组的方法,代码如下:
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 #Myemails.py 4 5 6 import re 7 8 def Myemails(e): 9 if len(e) >= 5:10 m = re.match(r'([a-zA-Z0-9]+?)/@([a-zA-Z0-9]+?)/.([a-zA-Z]+)', e)11 if m.group(0) == e:12 return '邮箱格式正确!'13 return '邮箱格式有误'14 15 e = raw_input("请输入email:")16 PRint e17 a = Myemails(e)18 print a
一点心得,如有错误,还请大神们指点,谢谢!
新闻热点
疑难解答