首先來個簡單的例子,利用Python實現匹配163郵箱的代碼:python
- __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!')
![](http://static.javashuo.com/static/loading.gif)
接着來一個匹配全部郵箱格式的代碼:spa
- __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):
- print('Email address is Right!')
- else:
- print('Please reset your right Email address!')
![](http://static.javashuo.com/static/loading.gif)