|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-06-18 06:05 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
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" );