liveBook · Manning

Greedy matching

Greedy matching is regular-expression behavior in which a quantifier matches as much text as possible while still allowing the overall pattern to match.

How 2 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

A greedy quantifier matches as many repetitions as possible while still allowing the remainder of the regular expression to match.

How it is used
Uses greedy and non-greedy quantifiers to control how regular expressions consume repeated characters.
How deep it goes
Explains default greediness, lazy modifiers, captures, and backtracking, stopping short of broader regexp-engine implementation.
Examples
Demonstrates digit runs, exclamation-delimited strings, and MatchData captures showing backtracking.
What you can do after
Diagnose regexp matches by predicting greedy consumption, applying lazy modifiers, and inspecting captures after backtracking.

Read how The Well-Grounded Rubyist, Fourth Edition explains greedy matching →

Tiny Python Projects: Learn coding and testing with puzzles and games

A regular-expression matching behavior in which a quantifier selects the longest possible substring that still permits the pattern to match.

How it is used
Uses greedy matching while extracting angle-bracket placeholders from Mad Libs input.
How deep it goes
Explains greedy, non-greedy, and delimiter-excluding patterns with interactive examples, but does not cover regex-engine internals.
Examples
Demonstrates `<.+>`, `<.+?>`, and `<[^<>]+>` against placeholder text and unbalanced brackets.
What you can do after
Diagnose/debug with Python regular expressions by identifying overmatching and choosing non-greedy or delimiter-excluding patterns.

Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains greedy matching →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.