The re
module in Python provides support for working with regular expressions. Regular expressions are used for matching patterns in text. Below is a list of some commonly used functions in the re
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python re Module Tutorial.
Python re Module Functions Table
Function | Description |
---|---|
re.compile() | Compiles a regular expression pattern into a regex object. This object can be used for matching using its match(), search(), and other methods. |
re.search() | Searches the entire string for the first location where the pattern matches and returns a match object. |
re.match() | Checks for a match only at the beginning of the string and returns a match object if found. |
re.fullmatch() | Checks if the entire string matches the pattern and returns a match object if it does. |
re.split() | Splits the string by occurrences of the pattern and returns a list of substrings. |
re.findall() | Finds all occurrences of the pattern in the string and returns them as a list. |
re.finditer() | Finds all occurrences of the pattern in the string and returns an iterator yielding match objects. |
re.sub() | Replaces the occurrences of the pattern in the string with the specified replacement and returns the new string. |
re.subn() | Similar to re.sub(), but also returns the number of substitutions made. |
re.escape() | Escapes all non-alphanumeric characters in the string, so they can be used in a regular expression. |
re.purge() | Clears the regular expression cache, which stores compiled patterns. |
For more detailed information on each function, refer to the official Python documentation.