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
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:
2 + 33 = ?
Subscribe to this entry?

 
 [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: Fri May 03 11:01:32 2024 UTC