You can construct a regular expression in Python using the re module that is natively shipped with the Python installation. There are several methods inside this module, such as search(), sub(), split(), compile(), and findall(), which will return the result as a regex object. Here is a summary of the use of each function:
Function Name |
Usage |
search() |
Search and match the first occurrence of the pattern. |
findall() |
Search and match all occurrences of the pattern and return the result as a list. |
Finditer() |
Search and match all occurrences of the pattern and return the result as an iterator. |
compile() |
Compile the regex into a pattern object that has methods for various operations, ... |