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