Skip to main content

Module reference

Module reference 

Source
Expand description

Executable specification: a deliberately simple, obviously-correct backtracking matcher defining regexr’s canonical match semantics.

This is the spec, not a production engine. It is intentionally written for clarity over speed (recursive backtracking with explicit continuations) so it can serve as the ground-truth oracle in differential tests: every real engine (Shift-Or, DFA, DFA-JIT, PikeVM, TaggedNFA interpreter and JIT, …) must agree with it. When they diverge, the engine is wrong, not the spec.

§Canonical semantics

Leftmost-first (Perl/PCRE/Python regex), greedy by default:

  • find returns the match at the earliest start position; among matches at that start, the one preferred by ordered alternation / greedy quantifiers.
  • Anchors follow PCRE/Python: ^=start-of-text, \A=start; $ matches at end of text or immediately before a trailing \n; (?m) switches ^/$ to line semantics; \b/\B use the ASCII word class [0-9A-Za-z_].

Operates on bytes; UnicodeCpClass decodes one UTF-8 codepoint.

Functions§

captures
Spans of every capture group of the leftmost-first match, group 0 first.
captures_from
captures resumed at byte offset from, the spec for captures_iter.
find
Finds the leftmost-first match of expr in input, returning byte offsets.
find_from
Finds the leftmost-first match of expr starting at or after byte offset from, returning byte offsets into the whole input.

Type Aliases§

Caps
Spans of every capture group of a match, indexed by group number; index 0 is the overall match. None means the group did not participate.