php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70328 wrong value of the maximum number of captured substrings in Subpatterns
Submitted: 2015-08-22 17:43 UTC Modified: 2015-08-23 13:54 UTC
From: jhdxr@php.net Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.6.12 OS: win10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jhdxr@php.net
New email:
PHP Version: OS:

 

 [2015-08-22 17:43 UTC] jhdxr@php.net
Description:
------------
As reported in #67576 , the doc says "The maximum number of captured substrings is 65535. ". However, the test script failed. It raised a warning: 
> Warning: preg_match(): Compilation failed: regular expression is too large at offset 21000

and followed by the instructions in #67576 , if I edit 7000 to 6552, everything works. So is it a documentation problem or I misunderstand something?

Test script:
---------------
<?php
ini_set("pcre.backtrack_limit", -1);
ini_set("pcre.recursion_limit", -1);
$test2 = str_repeat('a',10000);
//7000 is much smaller than 65535
if (preg_match('/'.str_repeat('(a)',7000).'/', $test2, $regs2)) {
    var_dump($regs2);
} else {
    echo 'Not find';
}

Expected result:
----------------
output the results of preg_match

Actual result:
--------------
Warning: preg_match(): Compilation failed: regular expression is too large at offset 21000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-23 13:44 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2015-08-23 13:44 UTC] cmb@php.net
The info in the PHP manual is likely to be based on this
changelog[1] entry for PCRE 3.5:

| 13. The limit of 99 on the number of capturing subpatterns has
| been removed. The new limit is 65535, which I hope will not be a
| "real" limit.

However, the error "regular expression is too large" is caused by
a compiled pattern exceeding a given size limit, see
<http://www.pcre.org/original/doc/html/pcrebuild.html#SEC12>.
Compiling a custom libpcre --with-link-size=3 and using this one,
makes the test script succeed.

[1] <http://www.pcre.org/original/changelog.txt>
 [2015-08-23 13:53 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=337592
Log: maximum number of captured substrings may not be reachable (fixes #70328)
 [2015-08-23 13:54 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2015-08-23 13:54 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 12:00:01 2026 UTC