Regular Expressions › Key Functions and Parameters
Michael BrenndoerferUpdated March 18, 20252 min read
Language AI HandbookAll chapters Part 1 of 67Text as Data
Regular Expressions › Key Functions and ParametersOne section · Sections in this chapter19 / 21 ↓
Sections in this chapter21
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
When working with regular expressions in Python, these are the essential functions and their most important parameters:
re.search(pattern, string, flags=0)
pattern: The regex pattern to search forstring: The text to search withinflags: Optional modifiers likere.IGNORECASE,re.MULTILINE- Returns: A match object for the first match, or
Noneif no match
re.findall(pattern, string, flags=0)
- Returns all non-overlapping matches as a list of strings
- If the pattern has groups, returns a list of tuples containing the groups
re.finditer(pattern, string, flags=0)
- Returns an iterator of match objects for all matches
- Use when you need position information or access to groups
re.sub(pattern, repl, string, count=0, flags=0)
repl: Replacement string or functioncount: Maximum number of replacements (0 means all)- Backreferences like
\1can be used in the replacement string
re.split(pattern, string, maxsplit=0, flags=0)
maxsplit: Maximum number of splits (0 means no limit)- Returns a list of strings split at pattern matches
re.compile(pattern, flags=0)
- Pre-compiles a pattern for repeated use
- Returns a compiled pattern object with the same methods
Common Flags
re.IGNORECASE(orre.I): Case-insensitive matchingre.MULTILINE(orre.M):^and$match at line boundariesre.DOTALL(orre.S):.matches newlinesre.VERBOSE(orre.X): Allow comments and whitespace in patterns