From Regular Expression Matching to Parsing

04/09/2018
by   Philip Bille, et al.
0

Given a regular expression R and a string Q the regular expression matching problem is to determine if Q is a member of the language generated by R. The classic textbook algorithm by Thompson [C. ACM 1968] constructs and simulates a non-deterministic finite automaton in O(nm) time and O(m) space, where n and m are the lengths of the string and the regular expression, respectively. Assuming the strong exponential time hypothesis Backurs and Indyk [FOCS 2016] showed that this result is nearly optimal. However, for most applications determining membership is insufficient and we need to compute how we match, i.e., to identify or replace matches or submatches in the string. Using backtracking we can extend Thompson's algorithm to solve this problem, called regular expression parsing, in the same asymptotic time but with a blow up in space to Ω(nm). Surprisingly, all existing approaches suffer the same or a similar quadratic blow up in space and no known solutions for regular expression parsing significantly improve this gap between matching and parsing. In this paper, we overcome this gap and present a new algorithm for regular expression parsing using O(nm) time and O(n + m) space. To achieve our result, we develop a novel divide and conquer approach similar in spirit to the classic divide and conquer technique by Hirshberg [C. ACM 1975] for computing a longest common subsequence of two strings in quadratic time and linear space. We show how to carefully decompose the problem to handle cyclic interactions in the automaton leading to a subproblem construction of independent interest. Finally, we generalize our techniques to convert other existing state-set transition algorithms for matching to parsing using only linear space.

READ FULL TEXT

Please sign up or login with your details

Forgot password? Click here to reset