PCRE2LIMITS(3)

πŸ’– PCRE2LIMITS(3) πŸ’–

okay bestie, so this is the manual for PCRE2 β€” aka Perl-compatible regular expressions (revised API) ✨ and this specific page is the one about all the size and other limitations. yes i know, limits are not the fun part, but you gotta know them or your regex is gonna ghost you at the worst possible moment. let's go πŸ¦‹


🌸 SIZE AND OTHER LIMITATIONS 🌸

so there are some size limitations in PCRE2, but honestly the devs are hoping they'll never actually matter in practice. manifesting that for you πŸ™βœ¨

  • the max size of a compiled pattern is approximately 64 thousand code units for the 8-bit and 16-bit libraries β€” that's assuming PCRE2 was compiled with the default internal linkage size, which is 2 bytes for these libraries. if you're the type of main character who needs to process truly enormous regular expressions, you can compile PCRE2 with an internal linkage size of 3 or 4 (and heads up: when building the 16-bit library, 3 gets rounded up to 4). check the README file in the source distribution and the pcre2build documentation for the deets. in those cases the limit is substantially larger β€” but πŸ’€ the speed of execution is slower. no free lunch, bestie. and in the 32-bit library, the internal linkage size is always 4.
  • the max length of a source pattern string is basically unlimited β€” it's the largest number a PCRE2_SIZE variable can hold. but !! the program that calls pcre2_compile() can specify a smaller limit if it wants to be like that.
  • the max length (in code units) of a subject string is one less than the largest number a PCRE2_SIZE variable can hold. PCRE2_SIZE is an unsigned integer type, usually defined as size_t. its maximum value (that is, ~(PCRE2_SIZE)0) is reserved as a special indicator for zero-terminated strings and unset offsets. so like, don't touch it, it's spoken for πŸ’…
  • all values in repeating quantifiers must be less than 65536. periodt.
  • okay this one has ✨layers✨ β€” 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 65535 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 it can be changed by the calling program.
  • there is no limit to the number of parenthesized groups πŸŽ‰ but there can be no more than 65535 capture groups, and there is a limit to the depth of nesting of parenthesized subpatterns of all kinds. why, you ask? because it limits 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 pcre2_set_parens_nest_limit() to set the limit in a compile context.
  • the max length of the name for a named capture group β€” as well as the number of such groups β€” is configurable at build time. the max length for the name defaults to 128 code units, and the max number of such groups defaults to 10000.
  • the max length of a name in a (*MARK), (*PRUNE), (*SKIP), or (*THEN) verb is 255 code units for the 8-bit library, and 65535 code units for the 16-bit and 32-bit libraries.
  • the max length of a string argument to a callout is the largest number a 32-bit unsigned integer can hold.
  • the max 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 🌈
ngl bestie, if you're bumping into these limits, you are truly built different. but now you know exactly where the walls are 🫢

πŸ’œ AUTHOR πŸ’œ

Philip Hazel Retired from University Computing Service Cambridge, England.


πŸŽ€ REVISION πŸŽ€

Last updated: 03 September 2025 Copyright (c) 1997-2023 University of Cambridge.


and that's a wrap on the limits page, bestie!! πŸ¦‹βœ¨ this was PCRE2 10.49, last updated 03 September 2025, and it lives at PCRE2LIMITS(3) in the Library Functions Manual πŸ’– go forth and regex responsibly, you absolute icon πŸ‘‘πŸ’…

πŸ“¦ where this page comes from