Sign in Start free

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:

ShorthandMeansOpposite
\da digit [0-9]\D
\wa word character [A-Za-z0-9_]\W
\swhitespace: 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