首先来个简单的例子,利用python实现匹配163邮箱的代码:
1
2
3
4
5
6
7
8
|
#-*- coding:utf-8 -*-
__author__ = '杨鑫'
import re
text = input ( "please input your email address:\n" ):
if re.match(r '[0-9a-za-z_]{0,19}@163.com' ,text):
print ( 'email address is right!' )
else :
print ( 'please reset your right email address!' )
|
接着来一个匹配所有邮箱格式的代码:
1
2
3
4
5
6
7
8
9
|
#-*- coding:utf-8 -*-
__author__ = '杨鑫'
import re
text = input ( "please input your email address:\n" )
if re.match(r '^[0-9a-za-z_]{0,19}@[0-9a-za-z]{1,13}\.[com,cn,net]{1,3}$' ,text):
#if re.match(r'[0-9a-za-z_]{0,19}@163.com',text):
print ( 'email address is right!' )
else :
print ( 'please reset your right email address!' )
|
以上这篇python实现正则表达式匹配任意的邮箱方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/u012965373/article/details/51395599