|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77428 mb_ereg_replace() doesn't replace a substitution variable
Submitted: 2019-01-08 01:47 UTC Modified: 2019-01-08 09:09 UTC
From: shin1x1 at gmail dot com Assigned:
Status: Closed Package: mbstring related
PHP Version: 7.3.0 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: shin1x1 at gmail dot com
New email:
PHP Version: OS:


 [2019-01-08 01:47 UTC] shin1x1 at gmail dot com
The substitution variable of mb_ereg_replace() is not working when a substitution variable is preceded by a backslash

If you look at the output is different for prior to PHP 7.3.0.

Test script:

var_dump(mb_ereg_replace('(%)', '\\\1', 'a%c'));

Expected result:
string(4) "a\%c"

Actual result:
string(5) "a\\1c"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-08 09:09 UTC]
Hrm, both the old and the new behavior are incorrect. The result should be "a\1c" here. '\\\1' is \\1 after unescaping, which should be a literal \ followed by a literal 1.

Not sure what to do with this one... It looks like this function just did not support escaping backslashes previously, so we might just have to go back to that for BC reasons.
 [2019-01-08 09:22 UTC]
Automatic comment on behalf of
Log: Fixed bug #77428
 [2019-01-08 09:22 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Aug 08 02:05:45 2022 UTC