Python实现正则表达式匹配任意的邮箱⾸先来个简单的例⼦,利⽤Python实现匹配163邮箱的代码:
[python]
正则表达式任意内容1. #-*- coding:utf-8 -*-
2. __author__ = '杨鑫'
3. import re
4. text = input("Please input your Email address:\n"):
5. if re.match(r'[0-9a-zA-Z_]{0,19}@163',text):
6. print('Email address is Right!')
7. else:
8. print('Please reset your right Email address!')
接着来⼀个匹配所有邮箱格式的代码:
[python]
1. #-*- coding:utf-8 -*-
2. __author__ = '杨鑫'
3. import re
4. text = input("Please input your Email address:\n")
5. if re.match(r'^[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}$',text):
6. #if re.match(r'[0-9a-zA-Z_]{0,19}@163',text):
7. print('Email address is Right!')
8. else:
9. print('Please reset your right Email address!')
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论