Explores structural regular expressions, a composition-based approach to text matching introduced by Rob Pike in the Sam editor. The article demonstrates how chaining smaller regex patterns can describe text structure more effectively than traditional line-by-line processing. It presents structex, a Rust crate that decouples the matching engine from actions, enabling custom text processing tools. Includes practical examples building grep-like and sed-like utilities, showing how operators like x (extract), y (split), g (guard), and v (inverted match) combine with actions to manipulate text programmatically.

17m read timeFrom sminez.dev
Post cover image
Table of contents
I love the smell of regular expressions in the morningWe're going to need a bigger parserToto, I don't think we're in Bell Labs anymoreWrapping up 5

Sort: