Match object
A match object is a regular-expression result structure containing matched text and providing access to its location and captured groups.
The Quick Python Book, Fourth Edition
A match object is a Python regular-expression result object that records the substring matched and provides access to captured groups and match positions.
- How it is used
- Uses match objects to extract named fields from records and compute replacements for matched substrings.
- How deep it goes
- Explains search results, named-group access, optional groups, and substitution callbacks, but leaves position-related methods undetailed.
- Examples
- Demonstrates extracting names and phone numbers from records and changing matched integers to strings ending in `.0`.
- What you can do after
- Apply it via Python `re` to inspect named matches and generate replacements from each match.
Read how The Quick Python Book, Fourth Edition explains match object →
Python How-To
A match object represents one regular-expression match and provides information about that match, such as its location.
- How it is used
- Uses successful regular-expression searches to inspect matched text, positions, and captured fields.
- How deep it goes
- Explains creation, truthiness, core inspection methods, numbered groups, and iteration, without descending into implementation internals.
- Examples
- Demonstrates matched text and spans, numbered groups, and parsing structured task records.
- What you can do after
- Diagnose regular-expression results by testing truthiness and printing matched text, captured groups, and character positions.
Related concepts
- groupuses · group() is a regular-expression match-object method that returns the complete match or the text captured by a specified capturing group.
- re.searchproduced by · re.search is a Python re-module function that searches a string for the first match of a regular-expression pattern and returns a match object or None.
- subproduced by · re.sub is a Python re-module function that returns a string with non-overlapping matches of a regular-expression pattern replaced by specified text or a callable result.
- conditional logicuses · Conditional logic is a programming technique that selects execution paths, actions, or result values according to evaluated conditions.
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.

