Table of Contents
Fetching ...

On the computational complexity of JavaScript regex matching

Victor Deng, Aurèle Barrière, Clément Pit-Claudel

Abstract

Despite widespread use, the complexity class of modern regular expression matching was not well-understood. Previous work proved that regular expression matching with backreferences and lookarounds was PSPACE-complete, but the proof was not mechanized and applied to an abstract regex language. This paper clarifies the question for JavaScript regular expressions. In this paper, we prove the following new results, with most core proofs mechanized in the Rocq proof assistant. We prove that JavaScript regex matching is indeed PSPACE-hard, even without negative lookarounds, and OptP-hard as well; that JavaScript regex matching without lower-bounded quantifiers (i.e. quantifiers with a non-zero minimum number of repetitions) is PSPACE-complete; and that JavaScript regex matching without lower-bounded quantifiers and without lookarounds is OptP-complete.

On the computational complexity of JavaScript regex matching

Abstract

Despite widespread use, the complexity class of modern regular expression matching was not well-understood. Previous work proved that regular expression matching with backreferences and lookarounds was PSPACE-complete, but the proof was not mechanized and applied to an abstract regex language. This paper clarifies the question for JavaScript regular expressions. In this paper, we prove the following new results, with most core proofs mechanized in the Rocq proof assistant. We prove that JavaScript regex matching is indeed PSPACE-hard, even without negative lookarounds, and OptP-hard as well; that JavaScript regex matching without lower-bounded quantifiers (i.e. quantifiers with a non-zero minimum number of repetitions) is PSPACE-complete; and that JavaScript regex matching without lower-bounded quantifiers and without lookarounds is OptP-complete.

Paper Structure

This paper contains 43 sections, 17 theorems, 24 equations, 5 figures.

Key Result

Theorem 1

The regex $r$ corresponding to a QBF $q$ matches the string $s$ corresponding to the QBF $q$ if and only if $q$ is true.

Figures (5)

  • Figure 1: JavaScript regex syntax (adapted for presentation purposes). Left: subset of regex constructs used in proof of PSPACE-hardness. Right: other regex constructs. Figure adapted from linden_popl26.
  • Figure 2: Examples of inductive rules of the semantics in linden_popl26.
  • Figure 3: Backtracking tree of regex $(_1 \mathrm{a|ab})\mathrm{c}$ on string "abc".
  • Figure 4: Definition of the size of a regex.
  • Figure 5: Definition of the expanded size of a regex. Modification compared to Fig. \ref{['fig:regex_size']} highlighted.

Theorems & Definitions (19)

  • definition 1
  • Theorem 1
  • Theorem 2
  • definition 2
  • Theorem 3
  • Theorem 4
  • Theorem 5
  • Theorem 6: fuel decrease
  • Theorem 7
  • Theorem 8
  • ...and 9 more