Improved Regular Expression Matching with Simple Backreferences
arXiv:2609.16914
Abstract
A regular expression with backreferences (rewb) specifies a set of strings formed by characters combined with concatenation, union, star operators, and backreferences. A backreference consists of a capturing group and a reference . The substring matched by the reference must match the substring matched by the corresponding capturing group. Given a rewb and a string , the rewb matching problem is to decide whether is one of the strings specified by . In full generality, rewb matching is NP-complete, but efficient solutions exist for various subclasses. In the paper, we focus on rewb containing a single capturing group and references. For this class, Uezato~[CPM 2026] gave an time and space algorithm, where is the length of the regular expression and is the length of the string . For the special case of , Nogami and Terauchi~[MFCS 2025] gave an time and space algorithm. On the other hand, Nogami, Nakamura, and Terauchi~[arXiv 2026] gave a conditional lower bound, showing that we cannot solve the problem in for any assuming the orthogonal vector hypothesis. Our main result is a new algorithm that runs in time and uses space. This improves the above results (by a factor of and , respectively) and the former's space bound (by a factor of ). We also show how to extend our algorithm to handle a slightly more general class of ordered and single-nested rewbs.