Re.search
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.
The Quick Python Book, Fourth Edition
search is a regular-expression pattern method that looks for the first match of a pattern within a string and returns a match object or None.
- How it is used
- Uses search to recognize patterns in text and retrieve matched data.
- How deep it goes
- Explains success and failure and named-group extraction; refers readers to Python documentation for a complete regex syntax list.
- Examples
- Counts lines containing hello and extracts names and phone numbers from records.
- What you can do after
- Apply it via Python’s re module to detect matching lines and extract named fields.
Read how The Quick Python Book, Fourth Edition explains re.search →
Python How-To
- How it is used
- Finds the first occurrence of a regular-expression pattern anywhere in a string.
- How deep it goes
- Explains direct and compiled calls, Match objects, positions, conditionals, and differences from match, findall, and finditer.
- Examples
- Uses digit-word patterns, matched text, spans, and direct calls on strings.
- What you can do after
- Apply it via Python's re module to locate a match and inspect its text and character positions.
Also covered in
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.
- NoneNone is Python’s singleton object representing the absence of a value or meaningful result.
Related concepts
- match objectproduces · A match object is a regular-expression result structure containing matched text and providing access to its location and captured groups.
- Noneproduces · None is Python’s singleton object representing the absence of a value or meaningful result.
- re.matchcontrasts with · re.match() is a Python regular-expression function that attempts to match a pattern at the beginning of a string.
- regular expressionused by · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- regex engineuses · A regular-expression engine is software that interprets regular-expression patterns and applies them to text for matching, searching, splitting, or transformation.
- similarity searchkind of · Similarity search is a retrieval technique that finds or ranks items by their similarity to a query, often by comparing feature or vector representations under a similarity or distance measure.
Questions about re.search
What is re.search?
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.
Which Manning books explain re.search?
The Quick Python Book, Fourth Edition and Python How-To.
What should I know before learning re.search?
Manning books that teach re.search usually introduce regular expression, function and None first.
What is the difference between re.search and re.match?
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. re.match() is a Python regular-expression function that attempts to match a pattern at the beginning of a string.
What is re.search a kind of?
Re.search is a kind of similarity search. Similarity search is a retrieval technique that finds or ranks items by their similarity to a query, often by comparing feature or vector representations under a similarity or distance measure.
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.

