[Paper Review] Unique Pattern Matching in Strings
This paper formalizes a unique pattern matching semantics for regular expressions using first-match and longest-match policies, proving that the common simulation of longest match via recursion and first match is incorrect. It presents a sound and complete type inference algorithm that constructs an unambiguous NFA to efficiently perform linear-time matching with correct subexpression associations.
Regular expression patterns are a key feature of document processing languages like Perl and XDuce. It is in this context that the first and longest match policies have been proposed to disambiguate the pattern matching process. We formally define a matching semantics with these policies and show that the generally accepted method of simulating longest match by first match and recursion is incorrect. We continue by solving the associated type inference problem, which consists in calculating for every subexpression the set of words the subexpression can still match when these policies are in effect, and show how this algorithm can be used to efficiently implement the matching process.
Motivation & Objective
- To formally define a unique matching semantics for regular expressions in strings, resolving ambiguity in pattern matching.
- To identify and correct the widespread misconception that longest match can be simulated via first match and recursion, which is shown to be incorrect.
- To solve the regular type inference problem: computing, for each subexpression, the set of words it can match under the unique matching semantics.
- To develop an efficient, linear-time matching algorithm based on unambiguous NFAs derived from the type inference process.
- To provide a syntactic- and system-independent approach to type inference, abstracting away from specific formalisms like those in XDuce.
Proposed method
- Defines a formal matching relation using two disambiguation rules: first match for alternation and longest match for Kleene star.
- Introduces a declarative type inference problem: for a pattern P and context language C, compute the language of subwords matched by each subexpression under unique matching.
- Proposes an algorithm H(P, C) that constructs a hyperautomaton (A, f), where f(n) is an NFA representing the language matched by subexpression n.
- Uses recursive construction rules based on pattern structure: for P = P1.P2, P = P1 + P2, P = P1*, to compute the type of each subexpression.
- Constructs an unambiguous NFA A that recognizes the full pattern and supports efficient matching via forward and backward state traversal.
- Employs a two-phase matching process: forward pass to compute reachable states, backward pass to reconstruct the unique accepting run and extract subexpression matches.
Experimental results
Research questions
- RQ1Is the standard simulation of longest match using first match and recursion correct for regular expression pattern matching?
- RQ2What is a sound and complete algorithm for regular type inference under unique matching semantics?
- RQ3Can the type inference process be implemented efficiently and yield an automaton that supports linear-time matching?
- RQ4How can the type inference be made independent of a specific regular expression type system or syntactic representation?
- RQ5What is the computational complexity of the type inference and matching process, and can it be optimized further?
Key findings
- The simulation of longest match via first match and recursion, commonly used in languages like XDuce, C Duce, and λre, is formally proven incorrect under the longest-match policy.
- The proposed type inference algorithm H(P, C) is both sound and complete, correctly computing the set of words each subexpression can match under unique matching.
- The resulting automaton A is unambiguous, ensuring at most one accepting run per input string, which enables deterministic and efficient matching.
- The algorithm supports linear-time matching by combining forward state propagation and backward run reconstruction to extract subexpression matches.
- The type inference process is independent of any specific regular expression formalism, relying only on language operations, which enhances clarity and generality.
- The construction of H(P, C) may involve exponential blowup in the worst case, though the paper conjectures a 2EXPTIME upper bound on its complexity.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.