php regex error preg_match():未知的修饰符'['

时间:2015-05-28 16:05:20

标签: php regex

我对Php Regex很新,但不知怎么地学习了一下并尝试如下,但得到的错误为:https://ideone.com/fTIyUK

以下是输出的整个代码: <?php $email = "paulw Paul Walker paulw 2014-12-28 07:18:09 paul@comp.com 2014-12-28 07:18:09 2014-12-28 07:18:09"; // Invalid email address $regex = "/[a-z] [A_Z] [A-Z] [A-Z] (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) /[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4} (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/"; if ( preg_match( $regex, $email ) ) { echo $email . " is a valid email. We can accept it."; } else { echo $email . " is an invalid email. Please try again."; } ?>

上述链接中的相同代码:

userid (string)   
first name(string)  
last name(string)  
userid(string)  
date  
email
date
date

请告诉我需要改变什么?

更新

输入: string(az)string(a-zA-Z)string(a-zA-Z)string(az)date(yyyy-mm-dd hh:mm:ss)emailid日期(yyyy-mm-dd hh:mm:ss)日期(yyyy-mm-dd hh:mm:ss)

8参数:

{{1}}

1 个答案:

答案 0 :(得分:1)

/

如果你仔细看到这个正则表达式,你在正则表达式中间有一个未转义的/,但是你使用$regex = "~[a-z]+ [A-Z]+ [A-Z]+ [A-Z]+ (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) [-\w.+]+@[-\w.+]+\.[a-zA-Z]{2,4} (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})~i"; 作为正则表达式分隔符。

使用此正则表达式替代替代正则表达式分隔符:

Task

RegEx Demo