Bug #14893 Updated: RE starting with (.*) might break

From: Date: Sun, 27 Jan 2002 06:03:40 +0000
Subject: Bug #14893 Updated: RE starting with (.*) might break
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-78211@lists.php.net to get a copy of this message
ID: 14893 Updated by: sterling Reported By: japhy@pobox.com Old Status: Open Status: Bogus Bug Type: PCRE related Operating System: SunOS PHP Version: 4.1.1 New Comment: a) Not a PHP bug (but its good to be aware of this issue, if you wouldn't mind please send a mail to sterling@php.net with any updates, etc.) b) not sure if this is really a bug, the way I read the 1st regex is: read in ab put that as \1 after a digit match \1 which is ab after the digit there is only b whereas in the second example you make the regex non-greedy, so therefore it matches from the beginning of the string and matches the ab from the lookahead assertion. I could be wrong, but either way its not a PHP bug ;) If you disagree please follow up at sterling@php.net regards, sterling Previous Comments: ------------------------------------------------------------------------ [2002-01-06 17:57:14] japhy@pobox.com Here's the problem: <? echo preg_match('/(.*)\d+\1/', 'ab1b'); ?> It fails, but it really shouldn't. You can fool the engine into not having the bug: <? echo preg_match('/(?=)(.*)\d+\1/', 'ab1b'); ?> The bug is thus: a regex that starts with .* can logically be made to start with an implicit anchor to the beginning of the string. However, this optimization can break the success of a regex if the .* is captured (as above) and used later (the back-reference \1). I've contacted the author of the PCRE package. ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14893&edit=1

« previous php.dev (#78211) next »