Regular expressions and Python

re is a standard Python library that's used to deal with Regex. Every default Python installation contains the re library. If the library doesn't exist, please refer to Chapter 2, Python and the Web – Using urllib and Requests, the Setting things up section, to learn how to set it up.

>>> in code represents the use of the Python IDE. It accepts the code or instructions it's given and displays the output on the next line.

Let's begin by importing re using the Python IDE and listing its properties using the dir() function:

>>> import re>>> print(dir(re)) #listing features from re

The following is the output of the preceding command:

['A', 'ASCII', 'DEBUG', 'DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', ...

Get Hands-On Web Scraping with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.