|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41077 Order may matter between brackets when using ereg()
Submitted: 2007-04-13 15:07 UTC Modified: 2007-05-18 15:06 UTC
From: aeolianmeson at blitzeclipse dot com Assigned:
Status: Wont fix Package: Regexps related
PHP Version: 5.1.2 OS: 2000 Server
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: aeolianmeson at blitzeclipse dot com
New email:
PHP Version: OS:


 [2007-04-13 15:07 UTC] aeolianmeson at blitzeclipse dot com
I needed to add a dash to a character class, so I appended it to the present character class definition. It turns out that it wouldn't accept unless I moved it to the middle.

Reproduce code:
// This works.
// $reg = "^[[:alnum:]_\.\-]+@[[:alnum:]_\.\-]+$";

// This does not work. The only difference 
// is the order of the last two accepted 
// characters in the first character class.

$reg = "^[a-z0-9_\-\.]+@[[:alnum:]_\.\-]+$";

var_dump(ereg($reg, ''));

Expected result:
Does match.

Actual result:
Does not match.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-13 16:25 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Read about strings with double quotes. The \\ won\'t be seen by the regexp engine.
 [2007-05-09 05:02 UTC] aeolianmeson at blitzeclipse dot com
I'm not exactly sure what you're referring to. I can use the exact same pattern with preg successfully. Can you confirm, or provide me a specific URL to clarify your explanation?

Consider the following, where preg returns true and ereg returns false:

$strEmail = "";
$strReg = "^[a-z0-9_\-\.]+@[a-z0-9_\-\.]+\.[a-z0-9_\-\.]+$";
var_dump(eregi($strReg, $strEmail));

$strReg = "/^[a-z0-9_\-\.]+@[a-z0-9_\-\.]+\.[a-z0-9_\-\.]+$/i";
var_dump(preg_match($strReg, $strEmail));

Thanks :) .

Dustin Oprea
 [2007-05-18 15:06 UTC]
Use PCRE functions.
I don't think anybody is going to maintain deprecated ereg() functions in the nearest future.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Sep 23 16:03:36 2021 UTC