liveBook · Manning

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.

How 2 Manning books explain it

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.

Read how Python How-To explains re.search →

Also covered in

What to know first

Related concepts

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.