Ready to Start Learning?

Sign in to check if you already have access, or get started with a purchase or membership.

Regular Expressions in Python

Regular expressions, aka regex, is incredibly common to help us parse data. Before we discuss how, let's consider a practical example by using US Phone numbers. The following are all valid written phone number formats:
  • +1-555-555-3121
  • 1-555-555-3121
  • 555-555-3121
  • +1(555)-555-3121
  • +15555553121
It's amazing that all of these numbers are the exact same just formatted slightly different. So how would we search a whole document for all possible derivations of phone number format?
"Machine learning!" you say. Well, that would probably work but it's overcomplicating this particular challenge. Instead, we can use pattern matching, aka regular expressions, to simplify the challenge.
Regular expressions are intimidating and take some time to wrap your head around. So I created this guide as a way to unpack how to effectively use Regular Expressions in Python. Many of these regex patterns and concepts overlap to other languages especially since Python regex was inspired by Perl.
Regular Expressions in Python

Lifetime access to this course

or get access to 500+ courses with a membership