ID:               16537
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-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] [EMAIL PROTECTED]

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

Reply via email to