Skip to content

Regex Patterns Every Developer Should Know Textbook

A free, self-paced textbook in 8 chapters. Read a chapter, then drill it with the 120 companion flashcards using spaced repetition.

8 chapters · 120 cards · Updated

Chapters

  1. 1Character Matching: Metacharacters, Shorthands, and Classes

    A regex engine begins by deciding which characters in the input stream a token can consume. The dot metacharacter . is the most permissive token: by default it matches any single c...

  2. 2Quantifiers: Greedy, Lazy, Possessive, and Exact

    Quantifiers tell the engine how many times to repeat the preceding token. The three fundamental quantifiers are * for zero or more, + for one or more, and ? for zero or one. The di...

  3. 3Anchors and Boundaries

    Anchors do not consume characters; they assert something about the current position in the input. The caret ^ matches the start of the string by default, and with the m flag it als...

  4. 4Groups, Captures, and Backreferences

    Parentheses do three distinct things in regex, and a good pattern keeps them straight. A capturing group, written (...), records the text it matches so it can be referenced later....

  5. 5Lookaround Assertions

    Lookarounds are zero-width assertions that test what is ahead or behind the current position without consuming characters. Positive lookahead, written (?=...), asserts that the upc...

  6. 6Flags, Modes, and Engine Features

    Flags change the global behavior of a regex. The case-insensitive flag i makes letter matching ignore case, so /hello/i matches Hello, HELLO, and hElLo. In Unicode-aware engines th...

  7. 7Practical Recipes for Validation and Extraction

    Real-world regex patterns solve recurring problems in input validation and text extraction. For an IPv4 address, each octet must lie in the range 0 to 255, which is most cleanly wr...

  8. 8Performance and Engine Internals

    Modern regex engines fall into two broad families with very different performance characteristics. A DFA, or deterministic finite automaton, runs in linear time, never backtracks,...

← Back to the Regex Patterns Every Developer Should Know deck