当前位置:网站首页>正则表达式(正则匹配)
正则表达式(正则匹配)
2022-06-30 17:41:00 【*小瑶】
正则表达式
正则表达式由两部分组成
原子(匹配内容)+元字符(匹配次数)
原子:
元字符:
最重要的就是**实践**了,大家可以看看下面这几个常用的,还可以去菜鸟教程里面看看其他的
这次展示其中几个函数(生活中的应用):
正则匹配邮箱号
正则匹配手机号
匹配网址
验证真实姓名为汉字
隐藏手机号码中数字
字符串分割成数组
<?php
//简单正则匹配:原子+元字符
$a="[email protected]_q.cm";
$b="19139567866";
$c="https://www.baidu.com";
$d="张三";
$check2=preg_match("/^\[email protected]\w+\.[0-9a-zA-Z]{2,4}$/",$a);//正则匹配邮箱号
$check1=preg_match("/^1[0-9]{10}$/",$b);//正则匹配邮箱号
$check3=preg_match("/^https?:\/\/\w+\.\w+/",$c);//匹配网址,最后的结束符$要去掉 同样可写成"/^(http)|(https):\/\/\w+\.\w+/"
$check4=preg_match("/^[^u4E00-u9FA5]{4,10}$/",$d);//验证真实姓名必须是汉字,一个汉字两个长度,[4,10]表示2-5个字
echo $check5=preg_replace("/[123]/","*",$b,2);//隐藏手机号码中数字,2表示只隐藏两个数字
echo"<br>";
$check6="张三,李四,王五#老六";//字符串分割成数组
$arry1=explode(",",$check6);
$arry2=preg_split("/[#,]/",$check6);
print_r($arry1);
echo "<br>";
print_r($arry2);
if($check1&&$check2&&$check3&&$check4)
{
echo('<br>zq');}
else{
echo("cuowu");}
边栏推荐
猜你喜欢

SaaS project management system solution for the financial service industry helps enterprises tap a broader growth service space

4个技巧告诉你,如何使用SMS促进业务销售?

PyTorch学习(三)

php利用队列解决迷宫问题

Classic problem of leetcode dynamic programming (I)

Tsinghua only ranks third? 2022 release of AI major ranking of Chinese Universities of soft science

屏幕显示技术进化史

Sword finger offer 17 Print from 1 to maximum n digits

CODING 正式入驻腾讯会议应用市场!

系统集成项目管理工程师认证高频考点:编制项目范围管理计划
随机推荐
Is it safe to open a mobile stock account? Is it reliable?
TeamTalk WinClient编译问题及解决方案
EasyNVR平台设备通道均在线,操作出现“网络请求失败”是什么原因?
《被讨厌的勇气:“自我启发之父”阿德勒的哲学课》
Adhering to the concept of 'home in China', 2022 BMW children's traffic safety training camp was launched
Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills
Solution of enterprise supply chain system in medical industry: realize collaborative visualization of medical digital intelligent supply chain
Vulnerability recurrence ----37. Apache unomi Remote Code Execution Vulnerability (cve-2020-13942)
Force deduction solution summary 1175- prime number arrangement
TiDB Dashboard里面可以写sql执行吗
Four tips tell you how to use SMS to promote business sales?
Hospital online consultation applet source code Internet hospital source code smart hospital source code
OneFlow源码解析:算子签名的自动推断
CODING 正式入驻腾讯会议应用市场!
Vscode status bar statusbar
mysql for update 死锁问题排查
Distributed transaction
漏洞复现----37、Apache Unomi 远程代码执行漏洞 (CVE-2020-13942)
云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
What if icloud photos cannot be uploaded or synchronized?