|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46890 Regex works in perl, not with preg_match
Submitted: 2008-12-17 20:51 UTC Modified: 2008-12-18 11:51 UTC
From: gohanman at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.8 OS: CentOS
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: gohanman at gmail dot com
New email:
PHP Version: OS:


 [2008-12-17 20:51 UTC] gohanman at gmail dot com
I'm having a preg_match function fail periodically. I finally found a specific input string that fails in PHP but works fine in Perl. I'm at a loss why.

Reproduce code:
$pattern = "/(\w\w\w) (\d+) (\d\d\d\d) (\d+):(\d\d)(\w)M/";
$input = "Dec 17 2008 2:23PM";
$rv = preg_match($pattern, $input, $groups);
echo var_dump($rv);

Expected result:
A non-zero result indicating the pattern matched.

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-18 08:50 UTC] php at degoulet dot net
[root@pix root]# cat a.php 
$pattern = "/(\w\w\w) (\d+) (\d\d\d\d) (\d+):(\d\d)(\w)M/";
$input = "Dec 17 2008 2:23PM";
$rv = preg_match($pattern, $input, $groups);
echo var_dump($rv);

[root@pix root]# php -v
PHP 5.2.8 (cli) (built: Dec 17 2008 16:18:21) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

[root@pix root]# php a.php 
 [2008-12-18 11:51 UTC]
it works here.
try to do a var_dump($groups); and watch it closely. (btw you shouldn't do 'echo var_dump'..)
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jul 07 04:03:36 2022 UTC