Regular expressions

A regular expression is usually taught as a string of punctuation and explained with a warning: avoid nested quantifiers, or your program might hang. Both halves of that have a picture. Compiled to an automaton — the way production engines that promise linear-time matching actually work — a pattern is a handful of states and arrows, and matching is reading the input once while every possible position is tracked at the same time. Left as a naive recursive matcher instead, the "might hang" is not a warning to take on faith: it is a number, the count of attempts a failed match had to try before giving up, and it is drawn here as a tree rather than described as a risk.

Pattern matching over plain text, without an automaton at all, lives in String matching. Finite-state machines in a different setting are in the ReAct loop.