首页 > Web开发 > 详细

php常用的正则表达式

时间:2020-08-10 12:53:13      阅读:79      评论:0      收藏:0      [点我收藏+]
$regex = [\u4e00-\u9fa5]; //匹配中文字符的正则表达式
$regex = ^[\u4E00-\u9FA5A-Za-z0-9]+$; or $regex = ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$; //中文、英文、数字但不包括下划线等符号
$regex = ^[a-zA-Z][a-zA-Z0-9_]{4,15}$; //帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线)
$regex = [^\x00-\xff]; //匹配双字节字符(包括汉字在内)
$regex = \n[\s| ]*\r; //匹配空行的正则表达式
$regex = /<(.*)>.*<\/\1>|<(.*) \/>/; //匹配HTML标记的正则表达式
$regex = (^\s*)|(\s*$); //匹配首尾空格的正则表达式
$regex = /(\d+)\.(\d+)\.(\d+)\.(\d+)/g; //匹配IP地址的正则表达式
$regex = \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*; //匹配Email地址的正则表达式
$regex = ^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$; //手机号
$regex = ^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$; //18位身份证号
$data = "***********";
if (preg_match($regex,$data)) {
  echo "验证成功";
} else {
  echo "验证失败";
}

 

php常用的正则表达式

原文:https://www.cnblogs.com/bloghuang/p/13468977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!