【发布时间】:2011-10-05 11:25:51
【问题描述】:
我有这个代码:
$string1 = "My name is 'Kate' and im fine";
$pattern = "My name is '(.*)' and im fine";
preg_match($pattern , $string1, $matches);
echo $matches[1];
当我运行它返回这个错误:
警告:preg_match() [function.preg-match]:分隔符不能是字母数字或反斜杠
【问题讨论】:
-
作为可能对其他人有帮助的注释,如果您将所有参数作为变量传递给
preg_match(),请确保您不会在函数中意外混淆变量的顺序调用,因为这也几乎肯定会导致出现同样的错误。 -
您的正则表达式字符串中需要一个分隔符
-
使用
$pattern = "/My name is '(.*)' and im fine/";
标签: php regex preg-match