當我運行如下:PHP的正則表達式不編譯
$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
您可以添加原始(未轉義)正則表達式在你的問題? – buckley
你有沒有試過不使用匿名函數? –
@EdHeal匿名函數有什麼問題? – wroniasty