Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “如何匹配”;(及)";正则表达式中的括号字符?_Php_Regex - Fatal编程技术网

Php “如何匹配”;(及)";正则表达式中的括号字符?

Php “如何匹配”;(及)";正则表达式中的括号字符?,php,regex,Php,Regex,我对正则表达式非常陌生 我想验证这样一个数字:1234567890121345678(123) 我知道如何匹配数字的前18位,但不知道如何允许下一位(以及其中的数字) 我目前正在使用此功能,该功能不完整,请帮助我 $string = "123456789012345678 (123)"; $pattern = '/^[0-9]{18}$/'; if(!preg_match($pattern, $string)){ echo 'valid'; } (和)是正则表达式元字符,因

我对正则表达式非常陌生

我想验证这样一个数字:1234567890121345678(123)

我知道如何匹配数字的前18位,但不知道如何允许下一位(以及其中的数字)

我目前正在使用此功能,该功能不完整,请帮助我

$string = "123456789012345678 (123)";
$pattern = '/^[0-9]{18}$/';
  if(!preg_match($pattern, $string)){
      echo 'valid';
  }
是正则表达式元字符,因此需要转义:

$pattern = '/^[0-9]{18} \([0-9]+\)$/';
是正则表达式元字符,因此需要转义:

$pattern = '/^[0-9]{18} \([0-9]+\)$/';