php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joei at mail dot com
New email:
PHP Version: OS:

 

 [2004-07-18 16:34 UTC] joei at mail dot com
Description:
------------
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";
else 
	echo "unmatch";
echo "<br>";

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

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

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-18 18:52 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

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.

eg,
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: Sat Dec 21 12:01:31 2024 UTC