Regular Expressions CheatSheet
Mar 28, 2021
Basics
Regular expressions always start with / / and g is for global.
/ expression /
, i.e/[A-Z]+/g
basic format/ name\?\*\\/
escape special characters with backslashes()
group with parentheses|
logical OR
Character classes
\w
word\d
digit\s
whitespace (tabs, line breaks)\W
NOT word\D
NOT digit\S
NOT whitespace\t
tabs,\n
line breaks.
any character
Anchors
^world
start of the stringsworld$
end of the string
Brackets
[xyz]
match any x, y, z[^xyz]
NOT x, y, z[B-X]
match any capital letters between B & X.
Quantification
viki|maria
match viki or mariaz{n}
n occurrencesz*
zero or multiple occurrencesz+
one or multiple occurrencesz{min, max}
min/max occurrencesz?
zero or one occurrences