5Shorthand classes \d \w \s
\d is a digit, \w a word character, \s whitespace – and the capitals mean the opposite.
Some classes are used so often that they have shortcuts:
| Shorthand | Means | Opposite |
|---|---|---|
\d | a digit [0-9] | \D |
\w | a word character [A-Za-z0-9_] | \W |
\s | whitespace: space, tab, line break… | \S |
They also work inside classes: [\d.] is a digit or a dot. A handy trick: [\s\S] matches absolutely any character, line breaks included.
Exercises
Lesson complete – well done!