English

Linear Time Subsequence and Supersequence Regex Matching

Data Structures and Algorithms 2025-08-21 v2 Formal Languages and Automata Theory

Abstract

It is well-known that checking whether a given string ww matches a given regular expression rr can be done in quadratic time O(wr)O(|w|\cdot |r|) and that this cannot be improved to a truly subquadratic running time of O((wr)1ϵ)O((|w|\cdot |r|)^{1-\epsilon}) assuming the strong exponential time hypothesis (SETH). We study a different matching paradigm where we ask instead whether ww has a subsequence that matches rr, and show that regex matching in this sense can be solved in linear time O(w+r)O(|w| + |r|). Further, the same holds if we ask for a supersequence. We show that the quantitative variants where we want to compute a longest or shortest subsequence or supersequence of ww that matches rr can be solved in O(wr)O(|w| \cdot |r|), i. e., asymptotically no worse than classical regex matching; and we show that O(w+r)O(|w| + |r|) is conditionally not possible for these problems. We also investigate these questions with respect to other natural string relations like the infix, prefix, left-extension or extension relation instead of the subsequence and supersequence relation. We further study the complexity of the universal problem where we ask if all subsequences (or supersequences, infixes, prefixes, left-extensions or extensions) of an input string satisfy a given regular expression.

Keywords

Cite

@article{arxiv.2504.16288,
  title  = {Linear Time Subsequence and Supersequence Regex Matching},
  author = {Antoine Amarilli and Florin Manea and Tina Ringleb and Markus L. Schmid},
  journal= {arXiv preprint arXiv:2504.16288},
  year   = {2025}
}

Comments

31 pages. Full version including all proofs

R2 v1 2026-06-28T23:07:51.830Z