匹配开头和结尾
字符 | 作用 |
---|---|
$ | 匹配字符串结尾 |
^ | 匹配字符串开头 |
示例 $
匹配 163.com的邮箱
import re
email_list = ["[email protected]", "[email protected]", "[email protected]"]
for email in email_list:
ret = re.match("[\w]{4,20}@163\.com", email)
if ret:
print("%s 是符合规定的邮件地址,匹配后的结果是:%s" % (email, ret.group()))
else:
print("这什么玩意儿")
# 运行结果:
[email protected] 是符合规定的邮件地址,匹配后的结果是:[email protected]
[email protected] 是符合规定的邮件地址,匹配后的结果是:[email protected]
这什么玩意儿
完善后
import re
email_list = ["[email protected]", "[email protected]", "[email protected]"]
for email in email_list:
ret = re.match("[\w]{4