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
- Finds matching text in strings, either to test a condition or to extract fields from a record.
- How deep it goes
- Works through compiled-pattern searches and match-object extraction, but leaves advanced search controls to documentation.
- Examples
- Counts file lines containing `hello` and extracts names and phone numbers from matching records.
- What you can do after
- Apply it via Python’s `re` module to test strings and retrieve named fields from successful matches.
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.
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.
- regular expressionused by · A formal pattern notation that describes sets of strings and enables text to be matched, searched, extracted, or transformed.
- re.matchcontrasts with · re.match() is a Python regular-expression function that attempts to match a pattern at the beginning of a string.
- Noneproduces · None is Python’s singleton object representing the absence of a value or meaningful result.
- 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 comparing their representations with a query according to 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.

