TIL: Structural Regular Expressions

38 year old treasure by Rob Pike.

Innes Anderson-Morrison on 2025-11-10:

Introduced by Rob Pike in his Sam text editor, and discussed in his 1987 paper, structural regular expressions provide a notation and semantics for composing the regular expressions we all know and love in order to more easily describe the structure of the text being searched.

Today I learned that Rob Pike suggested an enhancement to regular expressions called Structural Regular Expressions to more easily match and edit text across lines in a file, before I was even born. They're a little more complex than the usual global find-and-replace-with-regex that most editors provide, so I can understand why I've never run into them before now.