PHP正则表达式使用笔记
?
??? gfCheck = objRE.Test(strCheck) '符合正则式则返回true,反之则返回false
??? set objRE = nothing
??? end function
??? 常用的正则表达式
??? 1、非负整数:”^\d+$”
????17、空白行:\n\s*\r
?
一:匹配YYYY-MM-DD (([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)
2:匹配DD/MM/YYYY 或匹配D/M/YYYY
'/^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|'
??? ??? ??? ??? ??? ??? ??? ??? .'[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})\/((([13578]|1[2])|(0[13578]|1[02])'
??? ??? ??? ??? ??? ??? ??? ??? .'\/((0[1-9]|[12][0-9]|3[01])|([1-9]|[12][0-9]|3[1])))|(((0[469]|11)|([469]|11))'
??? ??? ??? ??? ??? ??? ??? ??? .'\/((0[1-9]|[12][0-9]|30)|([1-9]|[12][0-9]|30)))|'
??? ??? ??? ??? ??? ??? ??? ??? .'((02|2)\/((0[1-9]|[1][0-9]|2[0-8])|([1-9]|[1][0-9]|2[0-8]))'
??? ??? ??? ??? ??? ??? ??? ??? .')))|((([0-9]{2})((0[48]|[2468][048]|[13579][26])|([48]|[2468][048]|[13579][26]))|'
??? ??? ??? ??? ??? ??? ??? ??? .'((((0[48])|([48]))|[2468][048]|[3579][26])00))\/(02|2)\/29)$/';
?
3.验证全角
$strCheckPatten = “/^[^x00-xff]+$/”;
$input = “全角”;
if(preg_match($strCheckPatten,$input) == 0){
??? ??? return false;
}
else{
??? ??? return true;
}
===============================================================================================
url : var patt = /^([a-zA-z]+:\/\/)?([a-zA-Z0-9\u4e00-\u9fa5]+(\-[a-zA-Z0-9\u4e00-\u9fa5]+)*)(\.([a-zA-Z0-9\u4e00-\u9fa5]+(\-[a-zA-Z0-9\u4e00-\u9fa5]+)*))*(\?\S*)?$/i;
$pattern =? ."/^([a-zA-z]+:\/\/)?"
?????."([a-zA-Z0-9".chr(0xa1)."-".chr(0xff)."]+(\-[a-zA-Z0-9".chr(0xa1)."-".chr(0xff)."]+)*)"
?????."(\.([a-zA-Z0-9".chr(0xa1)."-".chr(0xff)."]+(\-[a-zA-Z0-9".chr(0xa1)."-".chr(0xff)."]+)*))*"
?????."(\?\S*)?$/i";
? 4.PHP中正则表达式中或普通的“”中的字符串用 \ 进行转义,都是从左到右进行的
如:echo “\\n”; 输出 "\n";?? echo "\""会报错
?
?
如有语言表达不当或错误之处,欢迎指正。