184
Chapter 7
• Remove sensitive information such as Social Security or credit
card numbers.
• Find common typos such as
multiple spaces between words, acciden-
tally accidentally repeated words, or multiple
exclamation marks at the
end of sentences. Those are annoying!!
Summary
While a computer can search for text quickly, it must be told precisely what
to look for. Regular expressions allow you to specify
the pattern of charac-
ters you are looking for, rather than the exact text itself. In fact, some word
processing and spreadsheet applications provide
find-and-replace features
that allow you to search using regular expressions.
The
re
module that comes with Python lets you compile
Regex
objects.
These objects have several methods:
search()
to find a single match,
findall()
to
find all matching instances, and
sub()
to do a find-and-replace substitution
of text.
You can find out more in the official Python documentation at
https://
docs.python.org/3/library/re.html. Another useful
resource is the tutorial
website
https://www.regular-expressions.info/.
Dostları ilə paylaş: