Compiling and Loops6:51 with Kenneth Love
Patterns, sets, groups, oh my! Now that we have so much control over what our patterns find and what we can create from the
Matches we get back, let's look at a way to turn regular expressions into a variable and then loop over our results.
re.compile(pattern, flags)- method to pre-compile and save a regular expression pattern, and any associated flags, for later use.
.groupdict()- method to generate a dictionary from a
Matchobject's groups. The keys will be the group names. The values will be the results of the patterns in the group.
re.finditer()- method to generate an iterable from the non-overlapping matches of a regular expression. Very handy for
.group()- method to access the content of a group.
0or none is the entire match.
1through how ever many groups you have will get that group. Or use a group's name to get it if you're using named groups.
You need to sign up for Treehouse in order to download course files.Sign up