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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC