且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将preg_match()与REGEX表达式一起使用时,未知修饰符'('

更新时间:2022-01-07 21:46:54

将表达式内的/字符转义为\/.

Escape the / characters inside the expression as \/.

$pattern = "/^([123]0|[012][1-9]|31)\/(0[1-9]|1[012])\/(19[0-9]{2}|2[0-9]{3})$/";

正如其他答案所指出的那样,***使用表达式中未使用的另一个定界符,例如~,以避免出现倾斜牙签"效应,使阅读起来更加困难.

As other answers have noted, it looks better to use another delimiter that isn't used in the expression, such as ~ to avoid the 'leaning toothpicks' effect that makes it harder to read.