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

yipeiwu_com7年前Python基础

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

#-*- 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 正则表达式匹配任意的邮箱

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

#-*- 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实现正则表达式匹配任意的邮箱方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Pytorch 神经网络—自定义数据集上实现教程

Pytorch 神经网络—自定义数据集上实现教程

第一步、导入需要的包 import os import scipy.io as sio import numpy as np import torch import torch.nn...

Python3安装pip工具的详细步骤

Python3安装pip工具的详细步骤

前几天安装Python的时候没有装上pip工具,所以只能现在手动安装了。 首先,访问https://bootstrap.pypa.io/get-pip.py这个网址,然后Ctrl+S将g...

python中类的一些方法分析

本文实例分析了python中类的一些方法,分享给大家供大家参考。具体分析如下: 先来看看下面这段代码: class Super: def delegate(self):...

python 实现读取一个excel多个sheet表并合并的方法

如下所示: import xlrd import pandas as pd from pandas import DataFrame DATA_DIR = 'E:/'...

python 根据pid杀死相应进程的方法

用python语言实现根据pid杀死相应进程 kill_process.py代码如下 #! /usr/bin/python # -*- coding: utf-8 -*- impo...