arXiv:2611.04852cs.DSNov 2026

Manuscript Offprint

arXiv:2611.04852

Faster Regular Expression Matching via Two-Dimensional Tabulation

Philip Bille, Inge Li Gørtz

Abstract

Regular expression matching asks whether a string of length nn belongs to the language described by a regular expression of length mm. We give an algorithm that solves this problem in linear space and O(nmlog⁡log⁡n/log⁡2n+n+m)O(nm \log \log n / \log^2 n + n + m) time. This improves the leading term of the previous best worst-case constant-alphabet time bound by a factor of log⁡n\sqrt{\log n}. The key new technique is a two-dimensional tabulation specialized to the regular expression.

1 Introduction

A regular expression RR specifies a set of strings formed by characters from an alphabet Σ\Sigma combined with concatenation (⊙)(\odot), union (∣)(|), and Kleene star (∗*) operators. For instance, (a∣(b⊙a))∗(a|(b \odot a))^* describes the set of strings of asas and bsbs such that every bb is followed by an aa. Given a regular expression RR and string QQ, the regular expression matching problem is to decide if QQ matches any of the strings specified by RR. Regular expressions are a fundamental concept in formal language theory, introduced by Kleene in the 1950s [15], and regular expression matching is a basic tool in computer science for searching and processing text. Standard tools such as grep and sed provide direct support for regular expression matching in files, and the scripting language perl [23] is a full programming language that supports regular expression matching easily. Regular expression matching appears in many large-scale data processing applications, such as internet traffic analysis [13, 16, 24], data mining [11], databases [17, 19], computational biology [21], and human-computer interaction [14].

A classic textbook algorithm for regular expression matching, due to Thompson [22] from 1968, constructs and simulates a nondeterministic finite automaton (NFA) AA in O(nm)O(nm) time, where nn is the length of QQ and mm is the total size of RR, counting each character symbol, occurrence of ϵ\epsilon, and operator once. The simulation processes QQ from left to right and computes a sequence of sets of states S0,…,SnS_0, \ldots, S_n such that SiS_i is the set of states in AA to which there is a path from the initial state that matches Q[1..i]Q[1..i]. In 1985 Galil [10] asked if a faster algorithm could be obtained. Subsequently, a sequence of results [4-7, 20] improved the O(nm)O(nm) bound using tabulation or word-level parallelism. In terms of nn and mm, the fastest known algorithm by Bille and Thorup [6] from 2009 achieves O(nmlog⁡log⁡nlog⁡1.5n+n+m)O(nm \frac{\log \log n}{\log^{1.5} n} + n + m) time.

More recently, several lower bounds suggest that polynomial improvements are not possible. First, Backurs and Indyk [3] showed in 2016 that we cannot solve regular expression matching in time O((nm)1−ϵ)O((nm)^{1-\epsilon}), for ϵ>0\epsilon > 0, assuming the orthogonal vectors hypothesis (OVH) (see also Bringmann, Larsen, and Grønlund [8]). Then, in 2018 Abboud and Bringmann [1] showed that we cannot solve the problem in time O(nm/log⁡7+ϵn)O(nm / \log^{7+\epsilon} n), for ϵ>0\epsilon > 0, assuming the formula-SAT hypothesis (FSH) [1] (we note that neither OVH or FSH are immediately affected by the recent refutation of the exponential time hypothesis). Thus, the best known upper bound saves a factor of log⁡3/2n/log⁡log⁡n\log^{3/2} n / \log \log n over the quadratic term nmnm, whereas the FSH-based lower bound only rules out savings of log⁡7+ϵn\log^{7+\epsilon} n, leaving a substantial polylogarithmic gap.