|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76376 preg_match fails to match pattern with backslash in the beginning of string.
Submitted: 2018-05-25 12:04 UTC Modified: 2018-05-25 13:17 UTC
From: alexander dot aka dot alegz at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: PCRE related
PHP Version: 7.0.30 OS: Centos 7
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: alexander dot aka dot alegz at gmail dot com
New email:
PHP Version: OS:


 [2018-05-25 12:04 UTC] alexander dot aka dot alegz at gmail dot com
OS: CentOS7
Source repo: remi
Version: PHP 7.0.30 (built: Apr 24 2018 21:28:23) ( NTS )

Reproduced both in cli and with web-server (as apache module).

Environment is pre-configured with bitrix-env ( on LXC container.

Test script:

$a = 'abc';
var_dump(preg_match('/^a/', $a));

$a = 'a\bc';
var_dump(preg_match('/^a\\b/', $a));

$a = '\abc';
var_dump(preg_match('/^\\a/', $a));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-25 13:17 UTC]
-Status: Open +Status: Not a bug -Package: Regexps related +Package: PCRE related -Assigned To: +Assigned To: cmb
 [2018-05-25 13:17 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

You need to escape the backslash twice, see
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 26 05:05:45 2022 UTC