当前位置:网站首页>正则表达式:邮箱匹配
正则表达式:邮箱匹配
2022-07-27 13:29:00 【不负韶华ღ】
格式概述
邮箱地址符合“名称@域名”规则。字符“@”在邮箱地址的“名称”和“域名”之间,邮箱地址名称只允许由英文字母、数字、下划线组成,域名只允许由英文字母、数字、“.”(点号)组成。
比如,[email protected]、[email protected]就是符合上述规则的邮箱。
模式说明
[\w][email protected][A-Za-z]+(\.[A-Za-z0-9]+){1,2}
分为两个部分,第一个部分[\w]+用于匹配邮箱的名称,第二个部分[\w]+(.[A-Za-z]+){1,2}用于匹配域名。
\w表示匹配数字、字母、下划线,[\w]+表示匹配一个或多个数字、字母、下划线;[A-Za-z]用于匹配一个字母,[A-Za-z]+用于匹配一个或多个字母,.[A-Za-z]+用于匹配以.(点号)开头并连接一个或多个字母,{1,2}表示匹配表达式(.[A-Za-z]+)一次或者两次。
注意,该正则表达式不是唯一的。还可以有其他的形式:
\b[\w][email protected][A-Za-z]+(\.[A-Za-z0-9]+){1,2}\b
^\[email protected][A-Za-z]+(\.[A-Za-z0-9]+){1,}$
使用示例
>>> import re
>>> pattern = r"[\w][email protected][A-Za-z]+(\.[A-Za-z0-9]+){1,2}\b"
# 符合格式邮箱号
>>> email = "[email protected]"
>>> re.match(pattern, email)
<re.Match object; span=(0, 16), match='[email protected]'>
# 不符合格式的邮箱号,包含特殊字符+
>>> email = "[email protected]"
>>> re.match(pattern, email)
None
边栏推荐
- 次小生成树【模板】
- Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
- JS什么是声明提前?函数与变量声明提前的先后顺序(执行上下文铺垫篇)
- Toward Fast, Flexible, and Robust Low-Light Image Enhancement(实现快速、灵活和稳健的弱光图像增强)CVPR2022
- 巨形象的图解 SQL
- DVWA全级别通关教程
- Ten thousand words detailed Google play online application standard package format AAB
- This points to problems, closures, and recursion
- One of yolox improvements: add CBAM, Se, ECA attention mechanism
- Research on multi label patent classification based on pre training model
猜你喜欢

【STM32】EXTI

Named entity recognition of Chinese electronic medical records based on Roberta WwM dynamic fusion model

面向流行性疾病科普的用户问题理解与答案内容组织

Interview eight part essay · TCP protocol

Slam overview Reading Note 4: a survey on deep learning for localization and mapping: towards the age of spatial 2020

JS epidemic at home, learning can't stop, 7000 word long text to help you thoroughly understand the prototype and prototype chain

One of yolox improvements: add CBAM, Se, ECA attention mechanism

基于招聘广告的岗位人才需求分析框架构建与实证研究
![[note] logistic regression](/img/2b/07cc3c26b1b34fbf2f09edaa33668e.jpg)
[note] logistic regression

文献翻译__tvreg v2:用于去噪、反卷积、修复和分割的变分成像方法(部分)
随机推荐
printf函数缓冲区问题
基于RoBERTa-wwm动态融合模型的中文电子病历命名实体识别
LeetCode·每日一题·592.分数加减运算·模拟
Import the virtual machine officially made by Kali Linux into Oracle VirtualBox
Redis
网上券商APP开户安全有保障吗?
连接ResourceManager 失败
SLAM综述阅读笔记七:Visual and Visual-Inertial SLAM: State of the Art, Classification,and Experimental 2021
poj3461 Oulipo【KMP】
arduino+ZE08-CH2O甲醛模块,输出甲醛含量
【科普】精度和分辨率的区别与联系
Navicate报错access violation at address 00000000
C language layered understanding (C language array)
Utnet hybrid transformer for medical image segmentation
融合迁移学习与文本增强的中文成语隐喻知识识别与关联研究
Slam overview Reading Note 4: a survey on deep learning for localization and mapping: towards the age of spatial 2020
log4j2 jdbc appender
SLAM综述阅读笔记四:A Survey on Deep Learning for Localization and Mapping: Towards the Age of Spatial 2020
Thread knowledge summary
Hdu4496 d-city [concurrent search]