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 captured text and provide context for replacement functions.
- How deep it goes
- Demonstrates named-group extraction and replacement callbacks, but only mentions additional match information and substring positions.
- Examples
- Uses name-and-phone records with an optional middle name and a callback that appends .0 to integer matches.
- What you can do after
- Apply Python's re module to retrieve named captures and construct match-dependent replacement strings.
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.
Also covered in
- Secrets of the JavaScript Ninja, Third EditionIn early access (MEAP)
What to know first
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
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 evaluates conditions to select among execution paths, actions, or result values.
Questions about match object
What is match object?
A match object is a regular-expression result structure containing matched text and providing access to its location and captured groups.
Which Manning books explain match object?
The Quick Python Book, Fourth Edition and Python How-To.
What should I know before learning match object?
Manning books that teach match object usually introduce regular expression and function first.
What are the parts of match object?
Match object includes match array.
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.

