Bug #16537 Updated: Bad backslash substitution w/ subexpressions
| From: | mfischer@php.net | Date: | Wed, 10 Apr 2002 21:14:56 +0000 |
| Subject: | Bug #16537 Updated: Bad backslash substitution w/ subexpressions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-4559@lists.php.net to get a copy of this message | ||
ID: 16537
Updated by: mfischer@php.net
Reported By: blueroom@digitalmente.net
-Status: Open
+Status: Closed
Bug Type: PCRE related
Operating System: Windows (2000)
PHP Version: 4.1.2
New Comment:
'\' and '\\' will both end up as a single '\' in the string which
effectively reads \( to the preg parser which means you escape the '('
and so don't use it's function to capture characters for backreferences
which renders the following ')' illegal since it tries to close a not
opened '('. Therefore, \ -> \ and \\ -> \ so you need \\\ to get \\ in
the string so you don't escape the (. Clear ? :)
Providing input data for such reports is essential.
Previous Comments:
------------------------------------------------------------------------
[2002-04-10 16:50:10] blueroom@digitalmente.net
Actually, this is quite simple.
Take this:
$preg_replace("/.\:\\.*?\\(.*?).gif/i","http://xpto/\\1.img",$string);
Theoretically, this would make a simple find-replace, but PHP throws
out a "unmatched parenthesis" error (Compilation failed: unmatched
parentheses at offset 12 blablabla...). With the only parentheses in
that regexp being the "(.*?)" in the middle, the error is awkward.
After some juggling I eventually found that it seems that in the
"\\(.*?)" part of the expression, the backslash before the parenthesis
gets replaced with an actual parenthesis BEFORE the double-backslash is
replaced with an actual backslash. I tried putting a space before the
parenthesis and no error appeared (obviously, the regexp didn't work
like that :).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=16537&edit=1