脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python实现正则表达式匹配任意的邮箱方法

Python实现正则表达式匹配任意的邮箱方法

2021-05-04 15:09杨鑫newlfe Python

今天小编就为大家分享一篇Python实现正则表达式匹配任意的邮箱方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

首先来个简单的例子,利用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!')

Python实现正则表达式匹配任意的邮箱方法

接着来一个匹配所有邮箱格式的代码:

?
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实现正则表达式匹配任意的邮箱方法

以上这篇python实现正则表达式匹配任意的邮箱方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/u012965373/article/details/51395599

延伸 · 阅读

精彩推荐