当前位置:网站首页>正则表达式:邮箱匹配
正则表达式:邮箱匹配
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
边栏推荐
- codeforces 1708E - DFS Trees
- Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
- 融合迁移学习与文本增强的中文成语隐喻知识识别与关联研究
- Arduino+ze08-ch2o formaldehyde module, output formaldehyde content
- Photo album based on gec6818 development board
- How to deploy open source Siyuan privately
- 2022牛客多校二_ E I
- Excellent basic methods of URL parsing using C language
- HDU4565 So Easy! [matrix multiplication] [derivation]
- Airport cloud business sign analysis
猜你喜欢

Airport cloud business sign analysis

Import the virtual machine officially made by Kali Linux into Oracle VirtualBox

Shell编程规范与变量

基于招聘广告的岗位人才需求分析框架构建与实证研究

Chapter 3 business function development (view clue details)

SLAM综述阅读笔记七:Visual and Visual-Inertial SLAM: State of the Art, Classification,and Experimental 2021

Chinese character style transfer --- antagonistic discriminative domain adaptation (L1)

SLAM综述阅读笔记六:基于图像语义的SLAM调研:移动机器人自主导航面向应用的解决方案 2020

PROFINET simulator tutorial

面向流行性疾病科普的用户问题理解与答案内容组织
随机推荐
log4j2 jdbc appender
YOLOX改进之一:添加CBAM、SE、ECA注意力机制
次小生成树【模板】
Simple encapsulation steps of request data request of uniapp
Airport cloud business sign analysis
知识关联视角下金融证券知识图谱构建与相关股票发现
在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机
How to make computers have public IP
np. Usage and difference of range() and range()
JS what is declaration in advance? The order of function and variable declaration in advance (the foreshadowing of execution context)
HDU4565 So Easy!【矩阵连乘】【推导】
汉字风格迁移篇---对抗性区分域适应(L1)Adversarial Discriminative Domain Adaptation
arduino+ZE08-CH2O甲醛模块,输出甲醛含量
连接ResourceManager 失败
STM32——电容触摸按键实验
10 practical uses of NFT
Understand JS execution context in an article
Photo album based on gec6818 development board
Is the security of online brokerage app account opening guaranteed?
[note] logistic regression