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.
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.
Related concepts
- BERTScoreimplemented by · BERTScore is an automatic text-generation evaluation metric that compares candidate and reference texts using contextual representations of their tokens.
- non-greedy quantifiercontrasts with · A non-greedy quantifier matches the fewest repetitions that allow the entire regular expression to match.
- regular expressionuses · A formal pattern notation that describes sets of strings and enables text to be matched, searched, extracted, or transformed.
- quantifierkind of · A regular-expression quantifier is syntax that specifies how many times a preceding pattern element may or must match.
- prefixaddresses · A prefix is an initial component or sequence of a larger word, string, name, path, or other structured value.
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.

