码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-09-23 21:30:26      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:tool   targe   blog   163邮箱   view   size   python   lease   fonts   

首先来个简单的例子,利用Python实现匹配163邮箱的代码:

 

 

[python] view plain copy
 
 print?
  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.com‘,text):  
  6.     print(‘Email address is Right!‘)  
  7. else:  
  8.     print(‘Please reset your right Email address!‘)  


技术分享

 

 

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

 

[python] view plain copy
 
 print?
  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.com‘,text):  
  7.     print(‘Email address is Right!‘)  
  8. else:  
  9.     print(‘Please reset your right Email address!‘)  


技术分享

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

标签:tool   targe   blog   163邮箱   view   size   python   lease   fonts   

原文地址:http://www.cnblogs.com/to-creat/p/7582441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!