ID: 29427 Updated by: [EMAIL PROTECTED] Reported By: x-g at monkeyblah dot com -Status: Open +Status: Bogus Bug Type: PCRE related Operating System: Windows XP PHP Version: 4.3.8 New Comment:
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 That's expected behaviour, because you're trying to match from the beginning of the string and using offset in the same time. Take a look at the example below. Following 2 lines work: preg_match("/[a-zA-Z]+/", $string, $matches, 0, 1) preg_match("/[a-zA-Z]+/", substr($string, 1), $matches, 0) and here second line will work: preg_match("/^[a-zA-Z]+/", $string, $matches, 0, 1) preg_match("/^[a-zA-Z]+/", substr($string, 1), $matches, 0) Previous Comments: ------------------------------------------------------------------------ [2004-08-16 05:36:39] skissane at iips dot mq dot edu dot au Also, confirmed this bugs existence in PHP 5.0.0. ------------------------------------------------------------------------ [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