Skip to main content

MAX_REGEX_CHARACTER_CLASSES

Constant MAX_REGEX_CHARACTER_CLASSES 

Source
const MAX_REGEX_CHARACTER_CLASSES: usize = 2000;
Expand description

The maximum number of character classes a pattern may contain.

Byte length cannot bound what a compile spends, and neither can size_limit, which covers only the compiled NFA. The memory goes to regex-syntax translating the AST into its HIR, where a character class expands to hundreds of Unicode ranges out of a handful of pattern bytes. \p{L} is five bytes, and under case folding [a-\x{2FFF}] is no cheaper, since the translator walks the range codepoint by codepoint keeping one range per fold mapping. See https://github.com/MaterializeInc/database-issues/issues/9907.

Counting rather than pricing is deliberate. Per-kind byte prices need calibrating against the pinned regex-syntax and fail silently when one is set too low, whereas a count only asks whether a kind can expand without bound, and over-counting merely costs a few legitimate patterns.

This and the byte limit are independent, and multiply out to a bound on one compile that regex_two_limits_bound_what_a_compile_spends holds against measurement.

Note: This number is mentioned in our user-facing docs at the “String operators” in the function reference.

NOTE: \p{L}{200000} stays one class in the AST. size_limit rejects its expansion later, in the NFA compiler.