|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66423 preg_match / preg_replace greedyness changes unpredictably with subject string
Submitted: 2014-01-06 02:40 UTC Modified: 2014-12-30 10:42 UTC
From: publi at web dot de Assigned:
Status: No Feedback Package: *Regular Expressions
PHP Version: Irrelevant OS: Debian Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: publi at web dot de
New email:
PHP Version: OS:


 [2014-01-06 02:40 UTC] publi at web dot de
I am using a shared debian host where I cannot easily upgrade to a newer version of PHP myself, currently it is PHP Version 5.3.3-7+squeeze18

I currently experience the expected behavior at roughly 85% of the inputs:
the preg_* modifiers "sU" make two ".*"s in the search string ungreedy.

Otherwise, at least the 1st occurrence of ".*" is not greedy.
Alterig it to ".*?" fixes the problem.

Behavior reproducibly depended on the subject strings of the search in my tests.
Since these are lengthy web pages, there is an archive with all source files at:
and the test script is also available to run at:
and more input files for additional tests ate at:

If you want more information or additional tests, feel free to contact me
via e-mail.

Test script:

Expected result:
file	 regex-1	 regex-2
6028	 1		 1
6245	 1		 1

Actual result:
file	 regex-1	 regex-2
6028	 1		 1
6245	 0		 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-06 03:52 UTC]
-Status: Open +Status: Feedback
 [2014-01-06 03:52 UTC]
Increase your pcre.backtrack_limit and try again.
 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Nov 30 20:03:37 2021 UTC