php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70304 Regex not matching on PHP7
Submitted: 2015-08-19 13:22 UTC Modified: 2016-07-20 23:01 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: giggsey at gmail dot com Assigned: cmb (profile)
Status: Closed Package: PCRE related
PHP Version: 7.0.0beta3 OS:
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: giggsey at gmail dot com
New email:
PHP Version: OS:

 

 [2015-08-19 13:22 UTC] giggsey at gmail dot com
Description:
------------
Regex: https://regex101.com/r/aZ7pL6/1 which matches the subject.

However, on PHP7 (and HHVM...), the regular expression fails to match anything.

If I change the first character matching from '[3-5789]' to '[3-578]', it starts working on PHP7.

Demo @ https://3v4l.org/0SMiZ

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

$subject = '512345678';

$failingPattern = '/^(?:[3-5789]\d{8})$/x';

$result = preg_match($failingPattern , $subject, $groups, PREG_OFFSET_CAPTURE);

var_dump($result, $groups);

Expected result:
----------------
int(1)
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(9) "512345678"
    [1]=>
    int(0)
  }
}


Actual result:
--------------
int(0)
array(0) {
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-19 14:42 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-08-19 14:42 UTC] cmb@php.net
That is somehow related to the PCRE JIT support. When pcre.jit=0,
the behavior is as expected, see <https://3v4l.org/ZkeV6>.
 [2015-08-20 04:34 UTC] laruence@php.net
-Status: Verified +Status: Analyzed
 [2015-08-20 04:34 UTC] laruence@php.net
see also: https://marc.info/?l=php-internals
 [2015-08-21 01:25 UTC] cmb@php.net
<http://markmail.org/thread/6bcffpbcobyi3ln7>, is not the problem
here (otherwise $result would be FALSE). Actually, in this case
pcre_exec() returns PCRE_ERROR_NOMATCH (and not
PCRE_ERROR_JIT_STACKLIMIT).
 [2015-08-26 13:46 UTC] hzmester at freemail dot hu
This is a corner case bug of range optimization in PCRE-JIT. I fixed it. Thank you for reporting it.
 [2015-10-01 18:40 UTC] giggsey at gmail dot com
Is this going to get included/fixed before PHP7 final?
 [2016-07-20 23:01 UTC] cmb@php.net
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-07-20 23:01 UTC] cmb@php.net
For the record: this bug has been fixed as of libpcre 8.38 (and
therefore as of PHP 7.0.3), see <https://3v4l.org/gdgLf>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 00:01:29 2024 UTC