蔭非常新的PHP正則表達式,但不知何故學會了一下,如下嘗試過,但得到的錯誤是:PHP Warning: preg_match(): Unknown modifier '[' in /home/3ZZyLt/prog.php on line 4
PHP的正則表達式錯誤的preg_match():未知的修飾詞「[」
這裏是整個代碼的輸出:從上面的鏈接https://ideone.com/fTIyUK
同一代碼:
<?php
$email = "paulw Paul Walker paulw 2014-12-28 07:18:09 [email protected] 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.+_][email protected][-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.";
}
?>
請告訴我有什麼需要改變?
更新:
輸入:串(AZ)的字符串(A-ZA-Z)的字符串(A-ZA-Z)的字符串(AZ)日期(YYYY-MM-DD HH:MM :SS)EMAILID日期(YYYY-MM-DD HH:MM:SS)日期(YYYY-MM-DD HH:MM:SS)
8參數:
userid (string)
first name(string)
last name(string)
userid(string)
date
email
date
date
這是可怕的正則表達式開始,並不會如預期反正工作。爲什麼不先在空間上分割?這是一個空格分隔的日誌/任何行,不是嗎? – mario
前四組只捕獲一個單個字符。即使錯誤消失,這也不起作用。 – Luceos
[如果你想驗證一封電子郵件,你可以使用filter_var()](http://stackoverflow.com/questions/19522092/should-i-use-filter-var-to-validate-email) – castis