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
 [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

Pull Requests

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: Sat Dec 21 14:01:32 2024 UTC