Lune

PLDI2023Top-tier venue

Repairing Regular Expressions for Extraction

Nariyoshi Chida, Tachio Terauchi

Abstract

While synthesizing and repairing regular expressions (regexes) based on Programming-by-Examples (PBE) methods have seen rapid progress in recent years, all existing works only support synthesizing or repairing regexes for membership testing, and the support for extraction is still an open problem. This paper fills the void by proposing the first PBE-based method for synthesizing and repairing regexes for extraction. Our work supports regexes that have real-world extensions such as backreferences and lookarounds. The extensions significantly affect the PBE-based synthesis and repair problem. In fact, we show that there are unsolvable instances of the problem if the synthesized regexes are not allowed to use the extensions, i.e., there is no regex without the extensions that correctly classify the given set of examples, whereas every problem instance is solvable if the extensions are allowed. This is in stark contrast to the case for the membership where every instance is guaranteed to have a solution expressible by a pure regex without the extensions. The main contribution of the paper is an algorithm to solve the PBE-based synthesis and repair problem for extraction. Our algorithm builds on existing methods for synthesizing and repairing regexes for membership testing, i.e., the enumerative search algorithms with SMT constraint solving. However, significant extensions are needed because the SMT constraints in the previous works are based on a non-deterministic semantics of regexes. Non-deterministic semantics is sound for membership but not for extraction, because which substrings are extracted depends on the deterministic behavior of actual regex engines. To address the issue, we propose a new SMT constraint generation method that respects the deterministic behavior of regex engines. For this, we first define a novel formal semantics of an actual regex engine as a deterministic big-step operational semantics, and use it as a basis to design the new SMT constraint generation method. The key idea to simulate the determinism in the formal semantics and the constraints is to consider continuations of regex matching and use them for disambiguation. We also propose two new search space pruning techniques called approximation-by-pure-regex and approximation-by-backreferences that make use of the extraction information in the examples. We have implemented the synthesis and repair algorithm in a tool called R3 (Repairing Regex for extRaction) and evaluated it on 50 regexes that contain real-world extensions. Our evaluation shows the effectiveness of the algorithm and that our new pruning techniques substantially prune the search space.

Ask Lune

Know where this paper stands in minutes, not an afternoon.

Lune can read the top-tier papers that cite it and the ones closest to it, and tells you what it claims, what came after and where it falls short, each point cited to the paper it comes from. No skimming, no AI slop.

3 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

its abstract · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Formal Verification for JavaScript Regular Expressions: A Proven Mechanized Semantics and Its Applications cites Linear Matching of JavaScript Regular Expressions
  • Formal Verification for JavaScript Regular Expressions: A Proven Mechanized Semantics and Its Applications cites Repairing Regex-Dependent String Functions
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers3

  1. Linear Matching of JavaScript Regular ExpressionsAurèle Barrière, Clément Pit-ClaudelPLDI 2024 · 11 citations
  2. Repairing Regex-Dependent String FunctionsNariyoshi Chida, Tachio TerauchiASE 2024 · 3 citations
  3. Formal Verification for JavaScript Regular Expressions: A Proven Mechanized Semantics and Its ApplicationsAurèle Barrière, Victor Deng, Clément Pit-ClaudelPOPL 2026

Related papers

  1. Repairing DoS Vulnerability of Real-World RegexesNariyoshi Chida, Tachio TerauchiS&P 2022 · 15 citations
  2. Repairing Regex-Dependent String-Manipulation ProgramsNariyoshi Chida, Tachio TerauchiCAV 2026
  3. Multi-modal synthesis of regular expressionsQiaochu Chen, Xinyu Wang, Xi Ye, Greg Durrett et al.PLDI 2020 · 81 citations
  4. FlashRegex: Deducing Anti-ReDoS Regexes from ExamplesYeting Li, Zhiwu Xu, Jialun Cao, Haiming Chen et al.ASE 2020 · 17 citations
  5. Interactive Program Synthesis by Augmented ExamplesTianyi Zhang, London Lowmanstone, Xinyu Wang, Elena L. GlassmanUIST 2020 · 57 citations
Dusk over the sea between two cliffs drawn in fine vertical lines