正则表达式不编译
当我运行下面的代码时:
$MATH_REGEX = '/(?=(?<!)$).(.+?)(?<!)$/';
preg_replace_callback($MATH_REGEX, function ($match) {
$latex_code = $match[0];
return lx($latex_code); //lx is defined elsewhere
}, "Test string $a=b$ .");
我得到这个:
$ php test.php PHP Warning: preg_replace_callback(): Compilation failed: missing ) at offset 26 in /home/sbird/public_html/faith/lib/view.php on line 26
我的正则表达式有什么问题?
编辑:
$ php --version PHP 5.3.2-1ubuntu4.15 with Suhosin-Patch (cli) (built: May 4 2012 00:38:52) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
你正在逃避一个(
:
/(?=(?<!)$).(.+?)(?<!)$/
here: ^^^
传递给preg_replace_callback
的结果字符串如下所示:
php > $MATH_REGEX = '/(?=(?<!)$).(.+?)(?<!)$/';
php > echo $MATH_REGEX;
/(?=(?<!)$).(.+?)(?<!)$/
^^ !!!
链接地址: http://www.djcxy.com/p/65077.html
上一篇: regex not compiling
下一篇: set("memory