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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 15:01:30 2024 UTC