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:
findreturns 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/\Buse 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 capturesresumed at byte offsetfrom, the spec forcaptures_iter.- find
- Finds the leftmost-first match of
exprininput, returning byte offsets. - find_
from - Finds the leftmost-first match of
exprstarting at or after byte offsetfrom, returning byte offsets into the wholeinput.
Type Aliases§
- Caps
- Spans of every capture group of a match, indexed by group number; index 0 is
the overall match.
Nonemeans the group did not participate.