You can match the characters not listed within the class by complementing the set. This is indicated by including a '^' as the first character of the class. For example, [^5] will match any character except '5' . If the caret appears elsewhere in a character class, it does not have special meaning. For example: $_{[5^]}$will match either a$_{'5'}$ or a '^' . Perhaps the most important metacharacter is the backslash,$_{\}$. As in Python string literals, the backslash can be followed by various characters to signal various special sequences. It’s also used to escape all the metacharacters so you can still match them in patterns; for example, if you need to match a$_{[}$ or$_{\}$, you can precede them with a backslash to remove their special meaning: \[ or \\ . Some of the special sequences beginning with '\' represent predefined sets of characters that are often useful, such as the set of digits, the set of letters, or the set of anything that isn’t whitespace. Let’s take an example: $_{\w}$matches any alphanumeric character. If the regex pattern is expressed in bytes, this is equivalent to the class [a-zA-Z0-9_] . If the regex pattern is a string, \w will match all the characters marked as letters in the Unicode database provided by the unicodedata module. You can use the more restricted definition of$_{\w}$ in a string pattern by supplying the$_{re.ASCII}$ flag when compiling the regular expression. The following list of special sequences isn’t complete. For a complete list of sequences and expanded class definitions for Unicode string patterns, see the last part of Regular Expression Syntax in the Standard Library reference. In general, the Unicode versions match any character that’s in the appropriate category in the Unicode database. These sequences can be included inside a character class. For example,$_{[\s,.]}$ is a character class that will match any whitespace character, or$_{','}$ or$_{'.'}$ . The final metacharacter in this section is$_{.}$ . It matches anything except a newline character, and there’s an alternate mode ($_{re.DOTALL}$ ) where it will match even a newline.$_{.}$is often used where you want to match “any character”. Being able to match varying sets of characters is the first thing regular expressions can do that isn’t already possible with the methods available on strings. However, if that was the only additional capability of regexes, they wouldn’t be much of an advance. Another capability is that you can specify that portions of the RE must be repeated a certain number of times. The first metacharacter for repeating things that we’ll look at is$_{*}$ .$_{*}$doesn’t match the literal character$_{'*'}$ ; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once. For example,$_{ca*t}$ will match$_{'ct'}$ (0$_{'a'}$ characters),$_{'cat'}$ (1$_{'a'}$ ),$_{'caaat'}$ (3$_{'a'}$ characters), and so forth. 2.2 Repeating Things Repetitions such as$_{*}$are greedy ; when repeating a RE, the matching engine will try to repeat it as many times as possible. If later portions of the pattern don’t match, the matching engine will then back up and try again with fewer repetitions. A step-by-step example will make this more obvious. Let’s consider the expression$_{a[bcd]*b}$ . This matches the letter$_{'a'}$ , zero or more letters from the class$_{[bcd]}$, and finally ends with a$_{'b'}$ . Now imagine matching this RE against the string$_{'abcbd'}$ . 3 \d Matches any decimal digit; this is equivalent to the class$_{[0-9]}$ . \D Matches any non-digit character; this is equivalent to the class$_{[^0-9]}$ . \s Matches any whitespace character; this is equivalent to the class$_{[ 	
\r\f\v]}$ . \S Matches any non-whitespace character; this is equivalent to the class$_{[^ 	
\r\f\v]}$. \w Matches any alphanumeric character; this is equivalent to the class$_{[a-zA-Z0-9_]}$ . \W Matches any non-alphanumeric character; this is equivalent to the class$_{[^a-zA-Z0-9_]}$ .