php.net |  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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gohanman at gmail dot com
New email:
PHP Version: OS:

 

 [2008-12-17 20:51 UTC] gohanman at gmail dot com
Description:
------------
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:
--------------
Zero.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-18 08:50 UTC] php at degoulet dot net
[root@pix root]# cat a.php 
<?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 
int(1)
 [2008-12-18 11:51 UTC] nlopess@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 11:01:31 2025 UTC