更新时间:2022-01-07 21:47:06
将表达式内的/
字符转义为\/
.
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.