当前位置:网站首页>正则表达式(正则匹配)
正则表达式(正则匹配)
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");}
边栏推荐
- Flink系列:checkpoint调优
- 4个技巧告诉你,如何使用SMS促进业务销售?
- 漏洞复现----37、Apache Unomi 远程代码执行漏洞 (CVE-2020-13942)
- LeetCode动态规划经典题(一)
- ONEFLOW source code parsing: automatic inference of operator signature
- 冰河老师的书
- 分布式场景下,你知道有几种生成唯一ID的方式嘛?
- Vulnerability recurrence ----37. Apache unomi Remote Code Execution Vulnerability (cve-2020-13942)
- 亲测flutter打包apk后大小,比较满意
- CODING 正式入驻腾讯会议应用市场!
猜你喜欢
Classic problem of leetcode dynamic programming (I)
autocad中文语言锁定只读警报怎么解决?
The easynvr platform equipment channels are all online. What is the reason for the "network request failure" in the operation?
php利用队列解决迷宫问题
屏幕显示技术进化史
漏洞复现----35、uWSGI PHP 目录遍历漏洞 (CVE-2018-7490)
Tsinghua only ranks third? 2022 release of AI major ranking of Chinese Universities of soft science
视频内容生产与消费创新
Adhering to the concept of 'home in China', 2022 BMW children's traffic safety training camp was launched
AI chief architect 10-aica-lanxiang, propeller frame design and core technology
随机推荐
Techo Youth2022学年高校公开课:直播连麦的背后,探索音视频技术如何应用
Dlib库实现人脸关键点检测(Opencv实现)
如何利用AI技术优化独立站客服系统?听听专家怎么说!
秉持'家在中国'理念 2022 BMW儿童交通安全训练营启动
Compilation problems and solutions of teamtalk winclient
麻烦问下 Flink支持同步数据到 sqlserver么
深度学习编译器的理解
冰河老师的书
NEON优化2:ARM优化高频指令总结
Flink系列:checkpoint调优
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
3.10 haas506 2.0开发教程-example-TFT
MRO industrial products procurement management system: enable MRO enterprise procurement nodes to build a new digital procurement system
详解单例模式
At present, the big guys are joining the two streams of flinksql, cdcmysql and Kafka, and the results are put into MySQL or KA
iCloud照片无法上传或同步怎么办?
Openlayers 卷帘地图
Tensorflow2 ten must know for deep learning
《Go题库·15》go struct 能不能比较?
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform