Regular Expressions

Regex, short for Regular Expressions, is a powerful system for searching text. Regular expressions are implemented in a variety of languages including java and python.

In Python, regular expressions are available through the re module:

import re

The following are some of the regular expression operations:

Regular Expressions

\d
Represents a character class that includes all digits (0-9). The inverse of this class is designated with a capital, &bsop;D, and will match any character that is not a digit.
re.findall()
Iterates over a string to find a subset of characters that match a specified pattern. It will return a list of every match that occurs in a given string.
re.search()
Iterates over a string to find a subset of characters that match a specified pattern.
re.split()
Divide a string into substrings at each occurrence of the specified character(s). This method is a good alternative to the default python .split() for instances that require matching multiple characters.
re.sub()
Replace matching substrings with a new string for all occurrences, or a specified number.
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn Python on Codecademy

Edit this page on GitHub

Contributors