|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-06-24 18:24 UTC] mjsherman at chartermi dot net
Description:
------------
preg_match, if passed a long subject string, fails unexpectedly.
I have read through the PCRE limitations, and can't see that this is one of them. I have tried increasing memory limit (to increase the stack) with the same results.
Cutoff and examples are below:
Reproduce code:
---------------
$subject = str_repeat('a',100);
$subject .= str_repeat('b', 4370);
$subject .= str_repeat('a', 100);
if (preg_match('/(.*).*?\1/',$subject)) {
echo "OK\n";
}
Expected result:
----------------
"OK" to be printed after matching 100 "a"s.
If 4370 is changed to 4369, then "OK" is printed.
Actual result:
--------------
With 4370 'b's, nothing is printed (failed preg_match)
With 4369 'b's, "OK" is printed (worked).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 12:00:01 2025 UTC |
An even simpler testcase: $data = str_repeat('a', 9999); preg_match('/(?:[a])*/', $data, $reg); Notice that the parenthesis is non-capturing, i.e. we don't even put a lot of elements in the $reg array.