Abstract
String constraint solving is a critical component of modern software verification and security analysis. However, existing solvers often struggle with the match operation, which identifies the position of a regular expression within a string. This paper introduces a specialized propagator for the match constraint implemented in the G-STRINGS solver. By leveraging a "dashed string" abstraction and a novel algorithm for leftmost matching, the proposed approach significantly improves efficiency and scalability. Evaluation on complex benchmarks shows that G-STRINGS outperforms state-of-the-art SMT and CP solvers by orders of magnitude.
Introduction
String manipulation is fundamental to modern programming, yet automated reasoning about strings remains a challenge. Most current constraint solvers focus on membership constraints—determining if a string belongs to a specific language. In practice, developers frequently use the match function to find the first occurrence of a pattern. Existing solvers typically handle this by decomposing the match operation into many simpler constraints, a process that is computationally expensive and often fails to prune the search space effectively, leading to performance bottlenecks.
Methods
The G-STRINGS solver introduces two key innovations to address these limitations:
- Dashed Strings Abstraction: Instead of representing strings as sequences of individual character variables, G-STRINGS uses "dashed strings." This abstraction represents a string as a sequence of blocks, where each block consists of a set of possible characters and associated minimum and maximum lengths. This allows the solver to represent large sets of strings compactly.
- The
PropMatchAlgorithm: This core propagator takes a Deterministic Finite Automaton (DFA) representing the regular expression and processes the dashed string. It performs a forward pass to identify the earliest possible match position and uses DFA state analysis (identifying universally accepting or rejecting states) to prune the domains of both the string and the integer match-position variables.
Evaluation and Results
The performance of G-STRINGS was evaluated against leading SMT solvers, CVC5 and Z3, as well as a decomposition-based version of G-STRINGS.
Stringy Latin Square
In the Stringy Latin Square benchmark, which uses match constraints to define row and column properties, the specialized G-STRINGS solver demonstrated exceptional scalability. It successfully solved instances up to size $n=26$ in approximately 32 seconds. In contrast, CVC5 failed to scale beyond $n=8$, and Z3 was unable to find solutions.
Shortest Matching Superstring
On the Shortest Matching Superstring problem, G-STRINGS proved to be the most robust solver. It found optimal solutions in 43.75% of cases and satisfied 100% of the instances. Its average time to the first solution (4.56s) was significantly lower than that of CVC5 (38.44s) and Z3 (174s).
Conclusion
The results confirm that native support for complex constraints like match is far superior to decomposition. By maintaining a global view of the constraint, the specialized propagator in G-STRINGS can prune the search space more aggressively. Future research will focus on extending these techniques to other complex operations, such as replace, and supporting non-regular features like back-references in regex engines.
Summary updated