Rob Pike's regular-expression matcher is about thirty lines of C split into three small mutually-recursive functions: one that searches anywhere in the string, one that matches at a fixed position, and one that handles repetition. It supports only four metacharacters, the dot, the star, and the two anchors, and that is the whole point. Kernighan estimated this subset covers roughly ninety-five percent of everyday regex use, so the matcher trades the long tail of features for a design a reader can hold in their head all at once. Ben Hoyt's port to Go grows it by a handful of lines, only because Go lacks a do-while loop and insists on braces, and the clarity survives the translation intact.
The instructive part is where the ninety-five percent line falls. Most of a full regex engine's complexity buys the last few percent of cases, and a design that consciously declines that tail can be smaller by an order of magnitude while still being useful for almost everything. The matcher even runs at a respectable speed, close to hand-written C and not embarrassingly far behind production engines, so minimalism here costs surprisingly little in practice. The honest caveat travels with it: this tiny version does not handle Unicode correctly, which is exactly the kind of real-world requirement that pushes the other five percent into a much larger program.
**Cross-Domain Connections**:
- [[Minimal Implementation as Art Form]] — the same aesthetic where stripping a program to its core is the achievement, not a limitation.
- [[The Simplest Parallel Abstraction Often Matches Hand-Tuned Code]] — a sibling case where the simple design performs close to the elaborate one, so the complexity was not buying much.
## Source
- [[20260802 Rob Pikes Simple C Regex Matcher in Go]] — Ben Hoyt, benhoyt.com, August 2022 — https://benhoyt.com/writings/rob-pike-regex/