Chapter 1 of 10All chapters
Chapter 1 of 10
What a regex is
Patterns, not programs.
The idea
A regular expression describes a set of strings. The engine walks the text trying to match that description, and reports where it succeeded.
- The same pattern language appears in editors, grep, and almost every programming language.
- Flavours differ in the corners, so a pattern is not always portable.
Where it fits
Regex is right for flat, predictable text: log lines, identifiers, simple formats. It cannot describe nesting, which is why HTML and JSON need real parsers.