|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16537 Bad backslash substitution w/ subexpressions
Submitted: 2002-04-10 16:50 UTC Modified: 2002-04-10 17:14 UTC
From: blueroom at digitalmente dot net Assigned:
Status: Closed Package: PCRE related
PHP Version: 4.1.2 OS: Windows (2000)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: blueroom at digitalmente dot net
New email:
PHP Version: OS:


 [2002-04-10 16:50 UTC] blueroom at digitalmente dot net
Actually, this is quite simple.
Take this:


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 :).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-10 17:14 UTC]
'\' 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.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Sep 23 06:03:35 2021 UTC