ID: 29427 Comment by: skissane at iips dot mq dot edu dot au Reported By: x-g at monkeyblah dot com Status: Open Bug Type: *Regular Expressions Operating System: Windows XP PHP Version: 4.3.8 New Comment:
Also, confirmed this bugs existence in PHP 5.0.0. Previous Comments: ------------------------------------------------------------------------ [2004-08-16 05:35:05] skissane at iips dot mq dot edu dot au The behaviour the manual implies is far more useful for my application. This is because I need to repeatedly match the beginning of substrings, but using substr(...) results in excessive memory usage, especially when the strings are very large. I would encourage this bug to be fixed ASAP. ------------------------------------------------------------------------ [2004-07-28 13:29:41] x-g at monkeyblah dot com Description: ------------ According to the manual, passing an offset to preg_match is equivalent to passing substr($string, $offset) to the function. This is not the case, however; regular expressions that match on beginning-of-string will not match if an offset is specified, but work fine if substr() is used in a supposedly equivalent manner. Either this is a problem with regular expressions giving unexpected behaviour, or perhaps the manual just need to be changed to reflect the difference. Reproduce code: --------------- $string = "abc def"; if (preg_match("/^[a-zA-Z]+/", $string, $matches, 0, 4)) echo "Matches\n"; else echo "Does not match\n"; if (preg_match("/^[a-zA-Z]+/", substr($string, 4), $matches, 0)) echo "Matches\n"; else echo "Does not match\n"; Expected result: ---------------- Matches Matches Actual result: -------------- Does not match Matches ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29427&edit=1