Python Tutorial: re Module - How to Write and Match Regular Expressions (Regex)

preview_player
Показать описание
In this Python Programming Tutorial, we will be learning how to read, write, and match regular expressions with the re module. Regular expressions are extremely useful for matching common patterns of text such as email addresses, phone numbers, URLs, etc. Learning how to do this within Python will allow us to quickly parse files and text for the information we need. Let's get started...

The code from this video can be found at:

Python String Slicing Tutorial:

Python Files Tutorial:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:

#Python
Рекомендации по теме
Комментарии
Автор

Corey, Your way of teaching is impeccable.

vishwa
Автор

Only good teachers prepare their lessons beforehand. This video is very informative, seamless, and so helpful

mightymaxglitches
Автор

This is the best regular expression teaching I have ever seen and believe it’s the best in the world. It covers almost everything in detail. Thank you Corey.

sadiqueahmed
Автор

I was real sceptical about this video because I didn't think I would grasp this concept in less than an hour. But im only 16 minutes in and im already in love with regular expressions! Thanks for making this video, you really made my week!

swaantjuh
Автор

Amazing tutorial. I gave up watching my professor's video and came to this.
This video needs to go viral!!

kinwong
Автор

OMG. how can you be so fluent and focused in a 53min video? You're the ultimate teacher. Thank you

mansouri
Автор

Man, you are an AMAZING teacher. I spent a whole lot of time trying to just be able to know how this worked, and I basically understood all of what you showed here, after watching this one video. thank you so much :)

theinfant
Автор

wow 7 years old, oldie but goodie, oh my goodness! not only was this fun, but also technically so sound it is still good. on top of that Corey has the patience and teaching skill that is rare with tech folks with deep technical know how. It helped me wrangle syslog files with inconsistent data with ease! I salute you sir! thanks so much!

yosiasz
Автор

Personal timestamps for second, third ..nth viewings:
0:00 - What are regular expressions.
0:52 - Re module and example intro.
1:28 - Raw string in Python
2:29 - Simple examples using re.compile and finditer
5:29 - Escaping special characters with a backslash
7:04 - Use regex to search for patterns. Use of meta-characters.
10:21 - Metacharacters continued. Anchors. Word boundaries.
12:04 - Anchors continued. ^ and $
13:55 - Practical examples. Matching phone numbers of patterns 123-456-7890 or 123.456.7890
18:58 - Precise matching using character-set
20:24- Character-set only matches one character in the set
21:27 - Match specific numbers. (800, 900 phone numbers)
22:57 - Role of dash(-) within a character set. Used to specify ranges.
24:16 - Role of carets (^) within a character set. Used to negate.
25:50 - Use of quantifiers to match more than one character at once.
31:20 - Groups. Match several different patterns
33:08 - Recap of previous concepts with examples. Matching email addresses
36:56- Deciphering existing regular expressions.
39:05 - Capturing information from groups. The group method in the match object
44:07 - Back reference to reference the captured group. Sub method to perform substitution
46:35 - findall method. Just returns the matches as a list of strings
47:58 - match method. Matches at the beginning of string.
49:30 - search method. Search the entire string.
50:08 - flags . Examples: ignorecase, multiline, verbose

sarithsn
Автор

After almost SEVEN YEARS, This video is still the best video on youtube for regex explaination. Thanks for the beautiful content👏

YoussufYasserAhmad
Автор

Simply superb. Corey has converted a complex concept into an easy and simple with his excellent teaching skills. Thank you Corey!!

vijaypracash
Автор

I was daunted by the thought of learning Regexes before I bumped in to this video. Now they make so much more sense, more importantly - in a logical way. Thanks a lot, Mr. Schafer.

S-wc
Автор

Thank you, Corey. I'm finally beginning to see the light at the end of the regex tunnel. 😀 Your video was a huge help.

BiancaAguglia
Автор

Brilliant work. This should be an example of how to teach anything on YouTube. Clear, concise, organized, and useful. When done, just ask yourself whether you now understand Regular Expressions. I am going to go try all this stuff out while it is fresh.

madjayhawk
Автор

I'm 2 minutes in, and have learned more than in past 3 days. Keep on the good work!

minasmorgul
Автор

Reading this topic in the books was giving me a lot of headaches, but your video just made it a breeze to understand the concept of RegEx. Thanks a ton

landrobin
Автор

It was such a great tutorial. This was my first time learning Regex, and I didn't know you'll break it down this much simpler. Great explanation!

Thanks a lot! ❤

deepaksoni
Автор

I searched across the 7 seas of the internet.














But I couldn't find any better tutorial in the internet. Cheers Corey

danielspector
Автор

Thank you so much for the tutorial. Through this entire 1 hr session I felt like I know regex properly. Very confident with my regex skillls.

preranajoshi
Автор

I commented on the other regex video you did, but last night and today I watched this video and again took really detailed notes. Today I was working on something where I had to strip off a bunch of characters and I thought, “you know what, I think I can just write a regular expression to do this instead of .strip().etcetc” So I wrote a pattern to match my string with re.compile(), then used var.sub(r’\groupnumberhere’), appended to a new list, and accomplished exactly what I needed to quickly and easily instead of having to .strip(), etc. I used to be so intimidated by this stuff; really can’t thank you enough!

JB-ikyf