Python實現正則表達式匹配任意的郵箱


首先來個簡單的例子,利用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!')  



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM