PythonIntermediate~4h

Regex

The notation, and the machine under it

Everyone can write a pattern that matches. Far fewer can say what one matched, where it started, or why it took half the line. This is the engine procedure, drilled on questions generated fresh: predict a span, read a capture, spell the one a requirement asks for — then write three against input built to break them.

Modules
6
Drills
9
Build steps
6
Time
~4h

Walk out able to

Read an unfamiliar pattern out loud, predict the exact text it matches, and name the token responsible when the result is wrong.

What this covers

01

Where a match begins

The scan, the classes, and what a quantifier binds to.

02

Greedy, lazy, anchored

The retreat that decides a span, and what stops it.

03

Groups and lookaround

Captures by number, backreferences, lookaround.

04

Patterns that go wrong

Extract, validate, and repair one that never returns.

The pitch

What you practise, and what you leave with

A field extractor over a log with two malformed lines, a validator against eighteen near-misses, and the repair of a pattern that hangs.

You will practise

  • Classes, quantifiers and what they bind to
  • Greedy against lazy, to the character
  • Anchors, captures, backreferences, lookaround
  • Writing one from scratch, repairing a broken one

Afterwards you can

  • Predict the exact text a pattern matches
  • Anchor a validator on purpose, not by luck
  • Read any capture out by number
  • Repair a pattern that never returns

Modules

6 modules, 31 items

Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.

  1. 1

    How the engine reads a pattern

    ~48 min

    Say where a match begins and what a class covers, before meeting a quantifier.

    • LessonWhy a pattern, and not find4 min
    • LessonFind where the match starts8 min
    • LessonRead the dot for what it is6 min
    • DrillSay what a class matches10 min
    • DrillMatch it whole, or not at all11 min
    • DrillSay it in the notation9 min
  2. 2

    Greedy, lazy and backtracking

    ~34 min

    Predict the exact text a quantifier takes, and say what made it stop there.

    • LessonWatch a quantifier give ground10 min
    • LessonTurn the run around6 min
    • LessonWhat the retreat costs6 min
    • DrillPredict the matched text12 min
  3. 3

    Anchors and boundaries

    ~27 min

    Pin a pattern to a position, and count what it finds without guessing.

    • LessonPin the pattern to a position9 min
    • LessonThe anchor you did not type6 min
    • DrillCount the matches12 min
  4. 4

    Groups, captures, backreferences

    ~42 min

    Read any capture out by number, and demand the same text a second time.

    • LessonWhat group one actually holds7 min
    • LessonThe other two jobs of a bracket7 min
    • LessonCaptures on the way out5 min
    • DrillRead a capture out12 min
    • DrillDemand the same text twice11 min
  5. 5

    Lookaround

    ~32 min

    Require a condition without taking the characters that satisfy it.

    • LessonAssert without consuming9 min
    • LessonStack conditions on one string6 min
    • LessonWhere a pattern is the wrong tool6 min
    • DrillSay what was consumed11 min
  6. 6

    Put it to work

    ~1h

    Read, write and repair real patterns against input that does not cooperate.

    • LessonRead a pattern somebody else wrote7 min
    • LessonName the token, then change it6 min
    • DrillPick the one-token repair10 min
    • Build stepCapture four fields from a log9 min
    • Build stepTotal only the successful requests8 min
    • Build stepWrite the ticket-code format8 min
    • Build stepMake it refuse the near-misses8 min
    • Build stepReproduce the hang, and time it7 min
    • Build stepRepair the pattern that hangs9 min

Read the pattern. Then predict exactly what it does.

The first item is free. ~4h of focused work, at your own pace.

Intermediate~4h6 modules