\d, \w and \s
Shorthand character classes matching digits 0-9,
word characters (letters and digits) and whitespace
respectively. Can be used inside and outside
character classes
[\d\s]
matches a
character
that is a
digit or
whitespace
Anchors
Anchors Description Example
^ (caret)
Matches at the start of the string to which the regular
expression pattern is applied. Matches a position rather than
a character. Most regular expression flavors have an option
to make the caret match after line breaks (i.e. at the start of a
line in a file) as well.
^.
matches
a in
abc\ndef.
Also
matches
d in
"multi-
line"
mode.
$
(dollar)
Matches at the end of the string to which the regular
expression pattern is applied. Matches a position rather than
a character. Most regular expression flavors have an option
to make the dollar match before line breaks (i.e. at the end of
a line in a file) as well. Also matches before the very last line
break if the string ends with a line break.
.$
matches f
in
abc\ndef.
Also
matches c
in "multi-
line"
mode.
\A
Matches at the start of the string to which the regular
expression pattern is applied to. Matches a position rather
than a character. Never matches after line breaks.
\A.
matches
a in abc
363
Anchors