我只是想从字符串中获取数字,其中数字包含在圆括号中。
我有以下代码:
$type_raw = $row['Type'];
$length_pattern = '^\(\d+\)$';
preg_match($type_raw,$length_pattern,$match,PREG_OFFSET_CAPTURE);
$length = $match[0];PHP显示以下错误:
“警告: preg_match()函数.preg-match:filename- -line number中的分隔符不能是字母数字或反斜杠->”
我的正则表达式模式是否有问题,或者可能是什么?
好的,我刚换了衣服
$length_pattern = '^\(\d+\)$';至
$length_pattern = '/^\(\d+\)$/';同样的错误也会出现吗?
发布于 2011-10-05 03:07:23
来自PHP.net
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )所以你的将会是:
$length_pattern = '/^\(\d+\)$/'; // with a delimiter "/"
preg_match($length_pattern,$type_raw,$matches,PREG_OFFSET_CAPTURE);发布于 2011-10-05 03:07:25
您需要为regex提供分隔符:
$length_pattern = '/^\(\d+\)$/';发布于 2011-10-05 03:08:03
method signature为:
int preg_match ( string $pattern ,
string $subject
[, array &$matches
[, int $flags = 0
[, int $offset = 0 ]]] )因此,您需要颠倒顺序,并为正则表达式提供分隔符,例如/^\(\d+\)$/
https://stackoverflow.com/questions/7652815
复制相似问题