| <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 2.0.26"><meta name="description" content="Details of size and other limits"><title>pcre2limits(3)</title><link rel="stylesheet" href="./css/document.css"><link rel="stylesheet" href="./css/standalone.css"><meta name="color-scheme" content="light dark"><meta name="theme-color" media="(prefers-color-scheme: light)" content="#0085cc"><meta name="theme-color" media="(prefers-color-scheme: dark)" content="#33b8ff"></head><body class="manpage toc2 toc-right offline-manual"><header class="offline-nav"><nav><a class="offline-index" href="./index.html">Index</a><a class="offline-home" href="https://www.pcre2.org/"><span aria-hidden="true">🌐︎</span> PCRE2 homepage</a></nav></header><main class="document-page"><header class="document-title"><h1>pcre2limits(3)</h1><p class="document-meta">PCRE2 10.50-DEV manual; updated <time datetime="2025-09-03">3 Sep 2025</time></p></header><div class="document-layout"><nav id="toc" class="toc2" role="doc-toc"><h2 id="toc-title">Contents</h2><ol class="toc-list level-1"><li><a href="#_size_and_other_limitations" title="Size and other limitations">Size and other limitations</a></li></ol></nav><article class="prose" id="content"><section class="doc-section level-1"><h2 id="_size_and_other_limitations">Size and other limitations</h2><p>There are some size limitations in PCRE2 but it is hoped that they will never | |
| in practice be relevant.</p> | |
| <p>The maximum size of a compiled pattern is 65,535 code units | |
| for the 8-bit and 16-bit libraries if PCRE2 is compiled with the default | |
| internal linkage size, which is 2 bytes for these libraries. If you want to | |
| process regular expressions that are truly enormous, you can compile PCRE2 with | |
| an internal linkage size of 3 or 4 (when building the 16-bit library, 3 is | |
| rounded up to 4). See the <code>README.md</code> file in the source distribution and the | |
| <a href="./pcre2build.html"><code>pcre2build</code></a> | |
| documentation for details. In these cases the limit is substantially larger. | |
| However, the speed of execution is slower. In the 32-bit library, the internal | |
| linkage size is always 4.</p> | |
| <p>The maximum length of a source pattern string is essentially unlimited; it is | |
| the largest number a <code class="type pcre2-api rouge"><span class="kt">PCRE2_SIZE</span></code> variable can hold. However, the program that | |
| calls <code class="function pcre2-api rouge"><span class="nf">pcre2_compile()</span></code> can specify a smaller limit.</p> | |
| <p>The maximum length (in code units) of a subject string is one less than the | |
| largest number a <code class="type pcre2-api rouge"><span class="kt">PCRE2_SIZE</span></code> variable can hold. <code class="type pcre2-api rouge"><span class="kt">PCRE2_SIZE</span></code> is an unsigned | |
| integer type, usually defined as <code class="type pcre2-api rouge"><span class="kt">size_t</span></code>. Its maximum value (that is | |
| <code class="c rouge" data-lang="c"><span class="o">~</span><span class="p">(</span><span class="kt">PCRE2_SIZE</span><span class="p">)</span><span class="mi">0</span></code>) is reserved as a special indicator for zero-terminated strings | |
| and unset offsets.</p> | |
| <p>All values in repeating quantifiers must be no greater than 65,535.</p> | |
| <p>There are two different limits that apply to branches of lookbehind assertions. | |
| If every branch in such an assertion matches a fixed number of characters, | |
| the maximum length of any branch is 65,535 characters. If any branch matches a | |
| variable number of characters, then the maximum matching length for every | |
| branch is limited. The default limit is set at compile time, defaulting to 255, | |
| but can be changed by the calling program.</p> | |
| <p>There is no limit to the number of parenthesized groups, but there can be no | |
| more than 65,535 capture groups, and there is a limit to the depth of nesting of | |
| parenthesized subpatterns of all kinds. This is imposed in order to limit the | |
| amount of system stack used at compile time. The default limit can be specified | |
| when PCRE2 is built; if not, the default is set to 250. An application can | |
| change this limit by calling <code class="function pcre2-api rouge"><span class="nf">pcre2_set_parens_nest_limit()</span></code> to set the limit in | |
| a compile context.</p> | |
| <p>The maximum length of the name for a named capture group as well as the number | |
| of such groups is configurable at build time. The maximum length for the name | |
| defaults to 128 code units, and the maximum number of such | |
| groups to 10,000.</p> | |
| <p>The maximum length of a name in a <code class="regex rouge"><span class="pcre2-semantic">(*MARK)</span></code>, <code class="regex rouge"><span class="pcre2-semantic">(*PRUNE)</span></code>, <code class="regex rouge"><span class="pcre2-semantic">(*SKIP)</span></code>, or <code class="regex rouge"><span class="pcre2-semantic">(*THEN)</span></code> verb | |
| is 255 code units for the 8-bit library and 65,535 code units for the 16-bit and | |
| 32-bit libraries.</p> | |
| <p>The maximum length of a string argument to a callout is the largest number a | |
| 32-bit unsigned integer can hold.</p> | |
| <p>The maximum amount of heap memory used for matching is controlled by the heap | |
| limit, which can be set in a pattern or in a match context. The default is a | |
| very large number, effectively unlimited.</p> | |
| <h2 id="_author" class="discrete">Author</h2> | |
| <p>Philip Hazel<br> | |
| Retired from University Computing Service<br> | |
| Cambridge, England.</p> | |
| <h2 id="_revision" class="discrete">Revision</h2> | |
| <p>Last updated: 03 September 2025<br> | |
| Copyright © 1997-2023 University of Cambridge.</p></section></article></div></main><footer class="offline-footer"></footer></body></html> |