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
Sets let us combine explicit characters and escape patterns into pieces that can be repeated multiple times. They also let us specify pieces that should be left out of any matches.
New terms
-
[abc]- this is a set of the characters 'a', 'b', and 'c'. It'll match any of those characters, in any order, but only once each. -
[a-z],[A-Z], or[a-zA-Z]- ranges that'll match any/all letters in the English alphabet in lowercase, uppercase, or both upper and lowercases. -
[0-9]- range that'll match any number from 0 to 9. You can change the ends to restrict the set.
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
We can do a huge amount already.
0:00
That's awesome.
0:00
But what if I know exactly the characters
that I want to match?
0:02
Or I need to make sure a certain character
isn't there?
0:05
Python's regular expressions engine has a
concept known as sets, and
0:08
these help us achieve exactly that.
0:11
We define a set of characters with square
brackets.
0:14
Any character in the brackets will be
looked for and
0:17
you can leave out duplicates.
0:19
So if we want to find the word apple, we'd
have a set with aple.
0:20
We can also define ranges in our sets.
0:24
If we want all of the lowercase letters,
we can define a set like a-z.
0:26
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