常用的正则表达式(en)

本文提供了一系列用于电子邮件地址及域名匹配的PHP正则表达式。包括简单与复杂域名、子域名等不同场景的匹配规则,并列举了匹配示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A Few Handy PHP Regular Expressions (RegEx)

 

Email Address:

'/^[^/W][a-zA-Z0-9_-]+(/.[a-zA-Z0-9_-]+)*/@[a-zA-Z0-9-]+(/.[a-zA-Z0-9-]+)*/.[a-zA-Z]{2,6}$/' 

Matches: john.doe@domain.edu This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , john_doe@do.main.edu This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , john-doe@do-main.edu This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , john@doe.gov.us This e-mail address is being protected from spam bots, you need JavaScript enabled to view it

Domain Name 1: This only matched simple domain names

'/^([a-zA-Z0-9-]+)/.[a-zA-Z]{2,6}$/'

Matches: domain.com, domain.net
Non-matches: sub.domain.com, domain.uni.cc, domain.ne.jp

Domain Name 2: This only matches complex domain names

'/^([a-zA-Z0-9-]+)/.[a-zA-Z]{2,3}/.[a-zA-Z]{2}$/'

Matches: domain.uni.cc, domain.ne.jp
Non-matches: sub.domain.com, domain.com

Sub Domain: This will only match for a sub domain of the specified domain

'/^[a-zA-Z0-9-]+/.realdomainname/.com$/ '

Matches: help.realdomainname.com, subdomain.realdomainname.com
Non-matches: sub.domain.com, help.realdomainname.net

Sub Domain: This will only match for a sub domain of the specified domain

'/^[a-zA-Z0-9-]+/.realdomainname/.com$/ '

Matches: help.realdomainname.com, subdomain.realdomainname.com
Non-matches: sub.domain.com, help.realdomainname.net

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值