Most commonly used module functions
in the re Python library.
re.compile(pattern, flags=0) -Compiles a
regular expression pattern into a regular
expression object.
re.search(pattern, string, flags=0) - Searches
a string for a match to the specified regular
expression pattern and returns the first
match found.
re.match(pattern, string, flags=0) - Attempts
to match the specified regular expression
pattern at the beginning of a string.
re.fullmatch(pattern, string, flags=0) -
Attempts to match the entire string with the
specified regular expression pattern.
re.split(pattern, string, maxsplit=0, flags=0)
- Splits a string into a list of substrings using
a regular expression pattern as the delimiter.
re.findall(pattern, string, flags=0) - Finds all
non-overlapping matches of a regular
expression pattern in a string and returns
them as a list of strings.
re.finditer(pattern, string, flags=0) - Finds
all non-overlapping matches of a regular
expression pattern in a string and returns
them as an iterator of match objects.
re.sub(pattern, repl, string, count=0,
flags=0) - Substitutes all occurrences of a
regular expression pattern in a string with a
replacement string.
re.subn(pattern, repl, string, count=0,
flags=0) - Substitutes all occurrences of a
regular expression pattern in a string with a
replacement string and returns a tuple
containing the new string and the number of
substitutions made.
Functions of a regular expression
object in Python.
search(string[, pos[, endpos]]) - Scan
through the string looking for a match to the
pattern, returning a match object, or None if
no match was found.
match(string[, pos[, endpos]]) - Determine
if the RE matches at the beginning of the
string, returning a match object, or None if
no match was found.
fullmatch(string[, pos[, endpos]]) - Match
the entire string to the pattern, returning a
match object, or None if no match was
found.
split(string[, maxsplit]) - Split the string by
the occurrences of the pattern.
findall(string[, pos[, endpos]]): Find all non-
overlapping matches of the pattern in the
string and return them as a list.
finditer(string[, pos[, endpos]]) - Find all
non-overlapping matches of the pattern in
the string and return them as an iterator.
sub(repl, string[, count]) - Return a new
string with all occurrences of the pattern
replaced by the replacement string.
subn(repl, string[, count]) - Perform the
same operation as sub(), but also return the
number of substitutions made.