Using regular expressions

A regular expression, or regex, is a sequence of characters and special metacharacters used to match a set of character strings. Regular expressions allow you to be more expressive with string-matching operations than just providing a simple substring. You can think of it as a pattern that you want to match with strings of different lengths, made up of different characters.

In the str.contains() method, we supplied the regular expression, wigg|drew. In this case, the vertical bar | is a metacharacter that acts as the OR operator, so this regular expression matches any string that contains the substring wigg or drew.

Metacharacters let you change how you make matches. When you provide a regular expression that contains ...

Get Hands-On Exploratory Data Analysis 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.