Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Patterns, sets, groups, oh my! Now that we have so much control over what our patterns find and what we can create from the Match
es we get back, let's look at a way to turn regular expressions into a variable and then loop over our results.
New terms
-
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 aMatch
object'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 forfor
loops. -
.group()
- method to access the content of a group.0
or none is the entire match.1
through 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.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up