Reputation: 40668
When I run the below:
$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$ .");
I get this:
$ 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
What is wrong with my regex?
EDIT:
$ 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
Upvotes: 1
Views: 84
Reputation: 8072
You are escaping a (
:
/(?=(?<!\\)\$).(.+?)(?<!\\)\$/
here: ^^^
The resulting string passed to preg_replace_callback
look like this:
php > $MATH_REGEX = '/(?=(?<!\\)\$).(.+?)(?<!\\)\$/';
php > echo $MATH_REGEX;
/(?=(?<!\)\$).(.+?)(?<!\)\$/
^^ !!!
Upvotes: 1