#100DaysOfCode in Python Transcripts
Chapter: Days 28-30: Regular Expressions
Lecture: Concepts: what did we learn

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So, let's do a quick wrap of what we've learned so far. When to not use regexes. Well if simple string operations do, use those.
0:13 Re.search versus re.match, re.match matches the whole string, re.search matches part of the string. Those are probably the main methods
0:22 you will be using on the re module. Capturing parentheses, to access part of the match use parentheses and you can use groups on the matching object
0:34 to get to the string. Your new best friend findall, one of my favorites. To get all the occurrences of a pattern in a string,
0:43 you can us findall and I showed you two examples. One is to get all the days or numbers out of the string
0:51 and it returns a list, and findall combined with counter one line of code a lot of stuff gets done. Compile for regexes, so you can use re.compile
1:01 to compile a regex to use over and over again. And you can add a verbose switch to make regular expressions
1:09 none space sensitive so you can line 'em out over multiple lines, making 'em more readable. String replacements, resub.
1:20 Again if you can use string replace do that but sometimes the pattern you want to match is more sophisticated and you need a regular expression.
1:28 The way to use read outsub methods is to define your pattern. Again I prefer you using a raw string to not to escape the back slashes.
1:42 And the second argument is to put in your replacement. And here's a little bit more advanced example. Where you use capturing parentheses to
1:50 port part of the matching string to the replacement arguments. And now it's your turn.


Talk Python's Mastodon Michael Kennedy's Mastodon