|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29245 ereg problem when use '\-'
Submitted: 2004-07-18 16:34 UTC Modified: 2004-07-19 09:16 UTC
From: joei at mail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 4.3.8 OS: Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: joei at mail dot com
New email:
PHP Version: OS:


 [2004-07-18 16:34 UTC] joei at mail dot com
I found ereg function in php 4.3.8 doesn't match some expression that I think it must be matched.

Look at example..

ereg('[\=\-]', 'a-b') = match
ereg('[\-\=]', 'a-b') = unmatch

I think 2 expressions is the same. But result is difference.

Reproduce code:
echo "ereg('[\=\-]', 'a-b') = " ;
if (ereg('[\=\-]', 'a-b'))
	echo "match";
	echo "unmatch";
echo "<br>";

echo "ereg('[\-\=]', 'a-b') = " ;
if (ereg('[\-\=]', 'a-b'))
	echo "match";
	echo "unmatch";
echo "<br>";

Expected result:
ereg('[\=\-]', 'a-b') = match
ereg('[\-\=]', 'a-b') = match

Actual result:
ereg('[\=\-]', 'a-b') = match
ereg('[\-\=]', 'a-b') = unmatch


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-18 18:52 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

When - is the 1st character in the range it does not need 
to be escaped, escaping it gives it special meaning.  
 [2004-07-19 08:59 UTC] joei at mail dot com
It is not only '\-' appear at first but everywhere except at the end, it doesn't match.

ereg('[\.\=\-]', 'a-b') = match
ereg('[\.\-\=]', 'a-b') = unmatch
 [2004-07-19 09:16 UTC] joei at mail dot com
I think it should to be add to documents that if you want to match '-' in character in the range, you have to place '-' at the first or '\-' at the end of range.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 11:01:32 2024 UTC