ID: 24242 Comment by: wiebe_j at hotmail dot com Reported By: madsen at sjovedyr dot dk Status: Bogus Bug Type: Regexps related Operating System: Debian Linux (Woody) Unstable PHP Version: 4.3.2 New Comment:
For me this is still a problem. The next 16 codelines, logically all should display a "y". But some display a "n". (Tried the escaped versions and the hex-versions) echo "<br><br>1."; echo "<br>".(preg_match("/^[\[\]]+$/","[]") ? "y" : "n" ); echo "<br>".(preg_match("/^[\]\[]+$/","[]") ? "y" : "n" ); echo "<br>".(preg_match("/^[\[\]]+$/","][") ? "y" : "n" ); echo "<br>".(preg_match("/^[\]\[]+$/","][") ? "y" : "n" ); echo "<br><br>2."; echo "<br>".(preg_match("/^[\x5B\x5D]+$/","[]") ? "y" : "n" ); echo "<br>".(preg_match("/^[\x5D\x5B]+$/","[]") ? "y" : "n" ); echo "<br>".(preg_match("/^[\x5B\x5D]+$/","][") ? "y" : "n" ); echo "<br>".(preg_match("/^[\x5D\x5B]+$/","][") ? "y" : "n" ); echo "<br><br>3."; echo "<br>".(ereg("^[\[\]]+$","[]") ? "y" : "n" ); echo "<br>".(ereg("^[\]\[]+$","[]") ? "y" : "n" ); echo "<br>".(ereg("^[\[\]]+$","][") ? "y" : "n" ); echo "<br>".(ereg("^[\]\[]+$","][") ? "y" : "n" ); echo "<br><br>4."; echo "<br>".(ereg("^[\x5B\x5D]+$","[]") ? "y" : "n" ); echo "<br>".(ereg("^[\x5D\x5B]+$","[]") ? "y" : "n" ); echo "<br>".(ereg("^[\x5B\x5D]+$","][") ? "y" : "n" ); echo "<br>".(ereg("^[\x5D\x5B]+$","][") ? "y" : "n" ); Previous Comments: ------------------------------------------------------------------------ [2003-06-18 06:08:28] madsen at sjovedyr dot dk Found the solution... Appearantly '[' and ']' doesn't need to be escaped (inconsistency?), but they have to be the first characters in the list of matches.... ------------------------------------------------------------------------ [2003-06-18 06:05:43] madsen at sjovedyr dot dk Description: ------------ Attempting to use ereg() for matching the date from an Apache error_log fails, when using the pattern: "^\[([^\]]*)\]" Intention of the pattern explained (in case I just can't see the error in it): ^\[ - Require first char in string to be a litteral '['. ([^\]]*) - Match any number of chars that is NOT ']'. \] - Match a litteral ']' When using this pattern in ereg(), like: ereg("^\[([^\]]*)\]", $string, $regs); $regs has returned empty, when printed by a print_r(); But then if I use "^\[(.*)\]" as my pattern, I get something in $regs, not the right match, since it then runs in 'greedy mode', and catches what's between *(* and *)*: [*(*Aug 25 2002 14:53:32] [error] [client: 88.99.111.222*)*] ... It's really confusing me... If this is not a bug I apologise, but I think I have taken every form of action required before reporting this as a bug. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=24242&edit=1