php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 - 18 = ?
Subscribe to this entry?

 
 [2018-05-25 12:04 UTC] alexander dot aka dot alegz at gmail dot com
Description:
------------
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 (https://training.bitrix24.com/support/training/course/index.php?COURSE_ID=113&LESSON_ID=9463&LESSON_PATH=9681.9461.9463) on LXC container.

Test script:
---------------
<?php

$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:
----------------
int(1)
int(1)
int(1)

Actual result:
--------------
int(1)
int(1)
int(0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

You need to escape the backslash twice, see
<https://3v4l.org/L3vvq>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC