#100DaysOfCode in Python Transcripts
Chapter: Days 28-30: Regular Expressions
Lecture: When not to use regexes

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's dive straight into a notebook I've prepared for this class. It's sometimes said that I have a problem, I use a regular expression knife too,
0:10 and in a sense that's true, that they're intimidating when you start. But there are only a few rules so get some practice and you will see that
0:19 they're not that difficult. Let's import the re module. First of all, there are cases that you don't want to use a regex.
0:27 The standard string methods are pretty powerful and cover some of your needs already. For example, I have a text.
0:34 'Awesome, I'm doing the #100DaysOfCode challenge' And we want to see if that string starts with 'Awesome' so no regular expression needed for that
0:43 you can just do text starts with Awesome and True. Or does it end with 'challenge'? It does. Or does the case insensitive version
1:02 of text has '100DaysOfCode' in it? Now for that you'd first want to lowercase the string and then you want to see if 100DaysOfCode is in that string.
1:20 And it is. And what about replacing? So I am bold and I'm taking 200 days of code. I don't recommend that by the way.
1:31 Well you can just do a text, replace 100 text strings by 200 and awesome, I'm doing the 200 days of code. So for these kind of string operations,
1:49 you don't really need a regex. So look at the string operations that are available in Python and use those instead.


Talk Python's Mastodon Michael Kennedy's Mastodon