Algorithm speeds up POSIX parsing to linear time for regex matching
Product-Linear POSIX Parsing
Formal Languages and Automata Theory
Summary
Regular expressions help computers find patterns in text, and POSIX rules tell us how to choose the best match when multiple are possible. Before, finding these POSIX matches took a lot longer as the expression got bigger. The authors developed a new algorithm that matches text using POSIX rules in a time proportional to both the pattern and text size, making the process faster and more efficient. Their method also uses less memory and works for several common matching modes.
What this means in practice
- •For software developers: Improve the speed and memory efficiency of regex engines in programming languages that use POSIX matching.
- •For data processing teams: Enhance text processing pipelines that rely on complex pattern matching with guaranteed performance scaling.
Authors
Yuya Uezato
Abstract
POSIX regular-expression matching reports capture spans determined by the parse tree that its disambiguation rules select. Thompson's classical construction decides whether an expression $E$ matches a text $w$ in product-linear time, $O(|E|\,|w|)$. Whether the POSIX parse can also be computed in product-linear time has remained open since the rules were standardized in 1992. For instance, the algorithm of Okui and Suzuki takes $O(|E|^2|w|)$ time after precomputation. We give, to our knowledge, the first algorithm that computes the POSIX parse and all capture spans in product-linear total time, $O(|E|\,|w|)$. It uses $O(|E|+|w|)$ working space and supports full matching, longest-prefix matching, and leftmost-longest search. The algorithm scans the text backward and keeps one preferred continuation per traversal state. It implements POSIX selection with lists of end positions of the open subexpressions, which it compares and updates in constant time.