php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70764 preg_match generate different results
Submitted: 2015-10-22 02:43 UTC Modified: 2015-10-22 04:56 UTC
From: zhihong dot chen dot cn at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.6.14 OS: ubuntu 14.04
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: zhihong dot chen dot cn at gmail dot com
New email:
PHP Version: OS:

 

 [2015-10-22 02:43 UTC] zhihong dot chen dot cn at gmail dot com
Description:
------------
var_dump(preg_match('/^\+?[\d\(\)-\s]+$/','18600003005'));

should generate true. 

in 5.3.28, it generate true

Test script:
---------------
<?PHP
var_dump(preg_match('/^\+?[\d\(\)-\s]+$/','18600003005'));


Expected result:
----------------
true

Actual result:
--------------
false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-22 04:56 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2015-10-22 04:56 UTC] rasmus@php.net
As the warning tells you, that regex is wrong.

    Warning: preg_match(): Compilation failed: invalid range in character class at offset 13

You are doing a character class range which is something like [a-z] but in your case you have [\d\(\)-\s] which makes no sense. A good way to debug regular expressions like this is to use https://regex101.com/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC