|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46664 preg_match returns false negative on > 100 kB strings for some patterns
Submitted: 2008-11-25 12:08 UTC Modified: 2008-11-25 12:20 UTC
From: patrik dot hirvinen at nemein dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 5.2.6 OS: Mac OS X 10.5
Private report: No CVE-ID: None
 [2008-11-25 12:08 UTC] patrik dot hirvinen at nemein dot com
preg_match fails for some patterns when the searched string exceeds around 100300 bytes. It matches for same strings if enough text is removed from the middle part which gets captured by the pattern when working correctly. Also the exact same regexp works fine for perl on unshortened output.

Reproduce code:
//foo.html >= 100 kB
$contents = file_get_contents("foo.html");
$matches = array();
preg_match('%<BODY\s*>.*?</H[1-6]>(.+?)</BODY>%si', $contents, $matches);
//$matches is empty

Expected result:
array(1) {
  string(12935) "/*lots of html*/

Actual result:
array(0) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-25 12:12 UTC] patrik dot hirvinen at nemein dot com
Also on at least on linux(debian) with PHP 5.2.0-8+etch11
 [2008-11-25 12:20 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You've reached the backtrack limit, check preg_last_error()
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 10:01:29 2024 UTC