Complete Regular Expressions Tutorial! (with exercises for practice)

preview_player
Показать описание
Practice your Python Pandas data science skills with problems on StrataScratch!

In this video we go through all the fundamentals of using regular expressions (regexes) to match patterns in programming.

In this video we cover the following:
- Character Sets [a-zA-Z0-9]
- Quantifiers *, +, ?, {3,5}
- Metacharacters ^ . | $
- Character Classes \b \s \w \d
- Groups
- Lookahead & Lookbehind assertions
- and more!

There is a detailed timeline down below.

In a future video we will apply what we learn in this one to the Python programming language (re library) -- subscribe to not miss that!

Resources!

-------------------------
Follow me on social media!

-------------------------

Practice your Python Pandas data science skills with problems on StrataScratch!

Learn data skills with hands-on exercises & tutorials at Datacamp!

Join the Python Army to get access to perks!

*I use affiliate links on the products that I recommend. I may earn a purchase commission or a referral bonus from the usage of these links.

-------------------------
Video timeline!
0:00 - Video overview & topics covered
1:43 - Basic regex syntax (building up an intuition)
4:23 - Character Sets Overview ([A-Za-z0-9])
5:57 - Quantifiers Guide (*, +, ?, {3,5})
9:30 - Guided Exercise: Find all words that don't use vowels
11:08 - Helpful cheat sheet to remember regex syntax in the real-world
12:47 - Matching words/patterns of a specific length ({3,5})
14:58 - OR operator overview
17:14 - Guided Exercise: Match valid sentences (starts with capital letter, ends with period)
21:18 - Character classes overview (\w, \b, \d, \s)
23:13 - Escaping Characters
25:02 - Practice Exercise #1: Write a regular expression to match meme text format
30:39 - Practice Exercise #2: Write a regular expression to match a specific date format
39:03 - Groups overview
50:16 - Lookahead & Lookbehind Assertions
1:00:18 - Practice Exercise #3: Detect if same word pops up multiple times in a sentence
1:06:04 - Practice Exercise #4: Password matching with rules
1:16:16 - Some final recommendations! (additional practice, chatgpt, etc.)
Рекомендации по теме
Комментарии
Автор

Oh man, I waited this so long, thank you for this video!

Fflaring
Автор

Hi, I hope you don't mind if I comment on names for symbols:
# is called 'pound' because on British keyboards it is the money symbol £ (try option#)
! is the exclamation point or mark that you referred to later
< I call the less-than symbol or angle bracket in HTML
> is the greater than symbol (it is bigger on the left side)
* is an Asterisk which means star. Commonly called just 'star'.
| is sometimes called a pipe or vertical bar
THANKS FOR A GREAT VIDEO ! WATCHED FROM BEGINNING TO END
and made a note of the PDF cheat sheet. Very useful.

Evan-e-cent
Автор

Finally I understood regex!!! Thank you

giacomobianchi
Автор

Always super helpful! Thank you Keith :)

stefanomedici
Автор

The legendary movie from Feb 1996 was Happy Gilmore! It surely contributed to the recent Kennedy Center honors for Adam Sandler. And a great video released on April 13, 2023 is the RegEx tutorial from Keith Galli, great job.

michaelpurtell
Автор

nothing better than entire you tube . your work is awesome . its really helpful man . thanks a lots

ahmadshabaz
Автор

at 38:52 I used
here inside [ ] square brackets we don't need to escape the dot (.) it is just dot, if we had used dot outside of square brackets then we had to escape dot. Cuz dot outside [] means everything except newline

rayedriasat
Автор

My body is regex. 🔎📃
10:50 Linguistically speaking, [y] can be a vowel, especially in words like "crypt". Pedantry of course, since it could just be added into the regex if needed. 🤓
36:40 Might not really be up to regex to do data validation. There are better tools for that. 🧰
In fact, integrating these into data workflows would be a good follow-up video for the future. ▶

anonviewerciv
Автор

You are the best! Thank you for this video
props from brazil

johnnybegood
Автор

Thank you for the video!

In negative lookbehind, try to use \b before the pattern you want to match. It has worked for me!

leonardoferreiracalazans
Автор

Really amazing video! Thanks for the great content!

For the part where it was allowing you to not escape the period in the square brackets, it's not sublime, you don't need to escape characters inside square brackets, although it won't complain if you do escape them. The only exception I can currently think of is the ^ symbol and only if you put it at the beginning.

javaluvawithjeremystones
Автор

not optimal but (0[1-9]|1[0-2]) would only match months 01-12

billsneddon
Автор

I would love to see a video on syntax trees and X' theory!

shawnabirnbaum
Автор

Ali sent me. Am so glad she did. You have some great videos.

maxximumb
Автор

Hi Keith, excellent video on regex.... One of the best videos made ever on youtube on glad i found your you make video on finding specific word in a sentence ex (i want to cancel my service. Please cancel my hbo, i want to can sail please console my service, im interested in cancelling) multiple words like this and we want to match word only (cancel | can sail |console service) and ommit any other word like 'cancel hbo' 'cancel bill' Any way can i reach out to you personally with sample. Thanks

FUNNEAS
Автор

Favorite tutor about to tackle a subject I've wanting to learn! Can't fight fate!

Let's

motlatsimoea
Автор

a period in a character class only matches a period, same for the other metacharacters like ? * +, the reason for this is there is no use to have a character match every character inside a character class, since for that you would not even need a character class, similar reasoning for the other metacharacters

DendrocnideMoroides
Автор

Hey, Thank you for the amazing content. Please Would you mind covering about End to End Pytorch series from the Problem statement, Data Collection, Modeling, Deployment, and Testing

JumaleAbdi-tuzh
Автор

Great video, Could you please prepare new video(tutorials) about ML?

xjcluup
Автор

Omg. Thanks to you, I could understand the regex. You're truly life saver

ucphattruong