Research Library · Idea
Regular expression matching
Regular expression matching is the task of finding substrings of a text that match a regular expression. A common approach compiles the expression into an automaton, which is then run over the text. Ken Thompson's 1968 CACM paper described compiling an expression into a nondeterministic finite automaton (NFA), and a simulation can track all reachable states at once 1.
In Russ Cox's 2007 account, this simulation runs in time proportional to the product of the expression length and the text length. Many widely used engines, including those of Perl, Python, PCRE, Ruby and Java, instead use recursive backtracking, which can take exponential time on certain pathological patterns. In Cox's benchmark, Perl needed over sixty seconds on a 29-character input where the NFA simulation needed about twenty microseconds 1.
Cox notes that backreferences are the main feature that automata-based matching does not handle without exponential cost. Deterministic automata were used by egrep from 1979 and later built on the fly 1.
Source · Regular Expression Matching Can Be Simple And Fast (opens in a new tab) · Russ Cox
References
Research articles
- The slowest input: algorithmic complexity attacks on hash tables, regexes and parsers · Software security
Papers
Programming Techniques: Regular expression search algorithm (opens in a new tab)
Locating specific character strings inside larger bodies of text is handled by a method that takes a regular expression as input. The method is realized as a compiler that reads the regular expression as its source language and generates an IBM 7094 program as its output. That generated program then reads the text to be searched and emits a signal each time an embedded string matches the given expression. The abstract also says that examples, problems, and solutions are presented alongside the description of the method and its implementation.
In the news
- GitLab Critical Patch Release: 19.5.1, 19.4.3, 19.3.6, 19.2.9, 19.1.9, 19.0.10, 18.11.13 · GitLab patch releases ·
- GitLab Critical Patch Release: 19.4.2, 19.3.5, 19.2.8 · GitLab patch releases ·
See what connects to it on the map of ideas →

SecSIG