Skip to main content

PCRE

Describes how recheck checks a regular expression of the pcre dialect.

Engine​

recheck follows the syntax and the semantics of PCRE2 10.49 as PHP's preg_* functions use it.

Settings​

The pcre dialect has no settings.

$ recheck --dialect=pcre '/^(a|a)*$/'

Flags and Units​

The matching unit is byte, or scalar-value with the u flag or (*UTF) (see Matching Units).

recheck supports the following pattern modifiers of PHP.

FlagPCRE2 optionInlineNotes
iPCRE2_CASELESS(?i)
mPCRE2_MULTILINE(?m)
nPCRE2_NO_AUTO_CAPTURE(?n)PHP 8.2 or later.
rPCRE2_EXTRA_CASELESS_RESTRICT(?r)PHP 8.4 or later.
sPCRE2_DOTALL(?s)
uPCRE2_UTF and PCRE2_UCP(*UTF)(*UCP)
xPCRE2_EXTENDED(?x)xx is x too, while (?xx) is PCRE2_EXTENDED_MORE.
APCRE2_ANCHOREDThe match starts at the start of the input.
DPCRE2_DOLLAR_ENDONLY$ matches only at the end of the input, unless with m.
JPCRE2_DUPNAMES(?J)
UPCRE2_UNGREEDY(?U)
SNo effect (PHP 7.3 or later).
XNo effect (PHP 7.3 or later, where an unknown escape is always an error).

Syntax Limitations​

The following constructs are not supported.

  • Recursion and subroutine calls (e.g. (?R), (?1), (?&name) and \g<name>), including (?(DEFINE)...) in a pattern with calls, are reported as unsupported.
  • Callouts (e.g. (?C1)), (*scan_substring:...) and script runs (e.g. (*sr:...)) are reported as unsupported.
  • Extended bracketed character classes ((?[ ... ])) are not supported yet, and they are reported as invalid.

Approximations​

  • PCRE2 has auto-possessification and JIT that recheck does not model, so an attack that recheck reports may not work on PCRE2, and the runtime-attack verification checks whether it does.
  • \G matches only at the start of the input, since recheck models a search from there, not one from a later position (e.g. the second match of preg_match_all).
  • PCRE2 skips the attempts that cannot match by its start-of-match optimizations (e.g. (*COMMIT)abc matches xyzabc in PCRE2, unless the pattern starts with (*NO_START_OPT)), and recheck does not model them.

Runtime-Attack Verification​

  • Command: php.
  • Matching: preg_match.
  • Engine limits: the backtrack limit.
  • Engine errors: the recursion limit and the JIT stack limit.
  • Environment variable: RECHECK_PHP.

The program runs with PHP's default settings of pcre.backtrack_limit, pcre.recursion_limit and pcre.jit.