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
Exact matches are great but most of the time you'll be looking for more generic and general things. Let's talk about the escape sequences we have available in regular expressions that let us match conceptual things like whitespace and word boundaries.
New terms
-
\w
- matches an Unicode word character. That's any letter, uppercase or lowercase, numbers, and the underscore character. In "new-releases-204",\w
would match each of the letters in "new" and "releases" and the numbers 2, 0, and 4. It wouldn't match the hyphens. -
\W
- is the opposite to\w
and matches anything that isn't an Unicode word character. In "new-releases-204",\W
would only match the hyphens. -
\s
- matches whitespace, so spaces, tabs, newlines, etc. -
\S
- matches everything that isn't whitespace. -
\d
- is how we match any number from 0 to 9 -
\D
- matches anything that isn't a number. -
\b
- matches word boundaries. What's a word boundary? It's the edges of word, defined by white space or the edges of the string. -
\B
- matches anything that isn't the edges of a word.
Two other escape characters that we didn't cover in the video are \A
and \Z
. These match the beginning and the end of the string, respectively. As we'll learn later, though, ^
and $
are more commonly used and usually what you actually want.
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