The PikeVM algorithm [
Cox 2009] is a popular linear-time matching algorithm for modern regexes with backtracking semantics. This algorithm is a descendant of NFA simulation [
Thompson 1968], where the NFA is extended to encode priority and is represented as interpreted bytecode. With its encoding of priority, the PikeVM algorithm supports capture groups, and greedy and lazy quantifiers, and returns the same result as a backtracking algorithm but without the exponential complexity. In the examples above, all the linear engines supporting capture groups implement a PikeVM (among other linear algorithms): the RE2 library
2, the Rust
Regex crate
3, the Go engine
4 and the linear engine of V8 for JavaScript regexes.
5However, the execution of the PikeVM algorithm is vastly different from the execution of a backtracking algorithm. It explores several paths in parallel, and discards some paths to avoid the exponential complexity. As a result, a PikeVM can be challenging to implement. Worse: small variations in semantics can affect the correctness of the base algorithm, and
Barrière and Pit-Claudel [2024] have shown that the PikeVM implementation deployed in V8 used to contain a semantic bug. While traditional NFA simulation itself has been formalized and verified many times (see
Section 7), handling priority requires new formal arguments, and to the best of our knowledge the PikeVM has never been formally verified despite its widespread use in modern engines.