PHP常用正则表达式精选

$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 = '
[s| ]*
';  //匹配空行的正则表达式

$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位身份证号
$regex = '[a-zA-z]+://[^s]* 或 ^http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$' 

$data = "***********";

if (preg_match($regex,$data)) {
    echo "验证成功";
} else {
    echo "你输入的是啥玩意?";
}
原文地址:https://www.cnblogs.com/yittxbug/p/10937183.html