#29245 [Bgs]: ereg problem when use '\-'

From: Date: Mon, 19 Jul 2004 07:16:49 +0000
Subject: #29245 [Bgs]: ereg problem when use '\-'
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-62619@lists.php.net to get a copy of this message
ID: 29245 User updated by: joei at mail dot com Reported By: joei at mail dot com Status: Bogus Bug Type: *Regular Expressions Operating System: Linux PHP Version: 4.3.8 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2004-07-19 08:59:47] 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-18 18:52:20] 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-18 16:34:20] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29245&edit=1

« previous php.bugs (#62619) next »