Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Regular Expressions in Python!
You have completed Regular Expressions in Python!
Preview
Now that we can search for just about anything, let's organize our results a bit better. Regular expressions give us indexed and named groups, both of which are super-handy.
New terms
-
([abc])- creates a group that contains a set for the letters 'a', 'b', and 'c'. This could be later accessed from theMatchobject as.group(1) -
(?P<name>[abc])- creates a named group that contains a set for the letters 'a', 'b', and 'c'. This could later be accessed from theMatchobject as.group('name'). -
.groups()- method to show all of the groups on aMatchobject. -
re.MULTILINEorre.M- flag to make a pattern regard lines in your text as the beginning or end of a string. -
^- specifies, in a pattern, the beginning of the string. -
$- specifies, in a pattern, the end of the string.
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
It's often really handy to have multiple
groups defined inside of your pattern, so
0:00
that you can later access just parts of
the text that you care about.
0:01
Like for our case, making a group for the
email address, and a group for
0:04
the phone number, and a group for
0:07
the name would make it a lot simpler later
to pull those out and use them.
0:09
So, at this point,
0:13
we've gotten to where we can catch pretty
much anything in our text file.
0:14
So I think what we should do now is we
should kind of just use all these
0:19
things at once.
0:21
This might get a little confusing, so
0:24
what we're gonna do is we're actually
gonna break these up into groups.
0:25
So let's let's start this out with our
normal print and re.findall.
0:29
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