Hardness of Regular Expression Matching with Extensions
Taisei Nogami, Tachio Terauchi
TL;DR
This work proves conditional lower bounds for regex matching when extended with backreference, intersection, and complement. It shows, via reductions from Orthogonal Vectors and from 3k-Clique, that 1-rewb and semi-ERE matching cannot achieve truly subquadratic time in the string length unless OVConjecture (and, respectively, k-Clique hypotheses) fail, even with polylogarithmic-length expressions. For ERE matching, the paper strengthens the claim by showing no $O(n^{\omega-\varepsilon}\mathrm{poly}(m))$-time algorithm is possible under the k-Clique Hypothesis and no combinatorial $O(n^{3-\varepsilon}\mathrm{poly}(m))$-time algorithm under the combinatorial k-Clique Hypothesis, implying Hopcroft–Ullman’s $O(n^{\omega}m)$ (and its combinatorial variants) are essentially optimal. The results illuminate why practical regex engines face fundamental limits when increasing expressive power and provide a principled explanation for the longevity of the classical $O(n^3 m)$ to $O(n^{\omega}m)$ bounds. Overall, the paper links core regex extensions to core circuit/graph problems, clarifying the trade-off between expressiveness and achievable running times in regex matching.
Abstract
The regular expression matching problem asks whether a given regular expression of length $m$ matches a given string of length $n$. As is well known, the problem can be solved in $O(nm)$ time using Thompson's algorithm. Moreover, recent studies have shown that the matching problem for regular expressions extended with a practical extension called lookaround can be solved in the same time complexity. In this work, we consider three well-known extensions to regular expressions called backreference, intersection and complement, and we show that, unlike in the case of lookaround, the matching problem for regular expressions extended with any of the three (for backreference, even when restricted to one capturing group) cannot be solved in $O(n^{2-\varepsilon} \mathrm{poly}(m))$ time for any constant $\varepsilon > 0$ under the Orthogonal Vectors Conjecture. Moreover, we study the matching problem for regular expressions extended with complement in more detail, which is also known as extended regular expression (ERE) matching. We show that there is no ERE matching algorithm that runs in $O(n^{ω-\varepsilon} \mathrm{poly}(m))$ time ($2 \le ω< 2.3716$ is the exponent of square matrix multiplication) for any constant $\varepsilon > 0$ under the $k$-Clique Hypothesis, and there is no combinatorial ERE matching algorithm that runs in $O(n^{3-\varepsilon} \mathrm{poly}(m))$ time for any constant $\varepsilon > 0$ under the Combinatorial $k$-Clique Hypothesis. This shows that the $O(n^3 m)$-time algorithm introduced by Hopcroft and Ullman in 1979 and recently improved by Bille et al. to run in $O(n^ωm)$ time using fast matrix multiplication was already optimal in a sense, and sheds light on why the theoretical computer science community has struggled to improve the time complexity of ERE matching with respect to $n$ and $m$ for more than 45 years.
