Escape Hatches5:23 with Kenneth Love
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.
\w- matches an Unicode word character. That's any letter, uppercase or lowercase, numbers, and the underscore character. In "new-releases-204",
\wwould 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
\wand matches anything that isn't an Unicode word character. In "new-releases-204",
\Wwould 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
\Z. These match the beginning and the end of the string, respectively. As we'll learn later, though,
$ are more commonly used and usually what you actually want.
You need to sign up for Treehouse in order to download course files.Sign up