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.
Lessons
1
Welcome
1:07
2
What we will do
1:07
3
The Reference Guide
1:06
4
A Simple Example
4:41
5
Issues with Regex Knowledge Gaps
1:46
6
Chunking Patterns
6:43
7
Optional Matches
3:43
8
Using Parentheses
2:36
9
Matching Pattern Ranges
6:08
10
The OR Operator
3:27
11
Groups & Grouping Patterns
6:48
12
Named groups
7:15
13
Using Letters
6:27
14
Metacharacters
13:36
15
Thank you and next steps
1:35