Character escapes act as shorthands for some common character classes.
Digit character —
The character escape
\d matches digit characters, from
9. It is equivalent to the character class
59 is also a pair of digits, most engines look for non-overlapping matches from left to right by default.
\D is the negation of
\d and is equivalent to
Word character —
\w matches characters deemed “word characters”. These include:
- lowercase alphabet —
- uppercase alphabet —
- digits —
- underscore —
It is thus equivalent to the character class
Whitespace character —
\s matches whitespace characters. The exact set of characters matched is dependent on the regex engine, but most include at least:
- tab —
- carriage return —
- new line —
- form feed —
Many also include vertical tabs (
\v). Unicode-aware engines usually match all characters in the
The technicalities, however, will usually not be important.
Any character —
While not a typical character escape,
. matches any1 character.