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设计】。

相关文章

python遍历文件夹并删除特定格式文件的示例

复制代码 代码如下:#!/usr/bin/python# -*- coding: utf-8 -*- import os def del_files(path):  ...

Python高级编程之继承问题详解(super与mro)

Python高级编程之继承问题详解(super与mro)

本文实例讲述了Python高级编程之继承问题。分享给大家供大家参考,具体如下: 多继承问题 1.单独调用父类: 一个子类同时继承自多个父类,又称菱形继承、钻石继承。 使用父类名.ini...

TensorFlow 模型载入方法汇总(小结)

TensorFlow 模型载入方法汇总(小结)

一、TensorFlow常规模型加载方法 保存模型 tf.train.Saver()类,.save(sess, ckpt文件目录)方法 参数名称...

python使用phoenixdb操作hbase的方法示例

今天看看怎样在 python 中使用 phoenixdb 来操作 hbase 安装 phoenixdb 库 pip install phoenixdb 例子 首先启动 que...

举例讲解Python常用模块

datetime 日期时间类,主要熟悉API,时区的概念与语言无关。 from datetime import datetime as dt dt.utcnow() # 系统UTC时...