just text: matches any string with the given text inside it
^ matches string that starts with the given text
$ matches string that ends with the given text
* zero or more
+ one or more
? zero or one
{n} n
occurrences
a|b or [ab] a or b
\d matches a digit
\w matches a word character (alphanumeric plus underscore)
\s matches a whitespace character
. matches any character
Anchors
just text
abc
matches any string that has the text abc in it
^
^abc
matches any string that starts with abc
$
abc$
matches any string that ends with abc
exact match
^abc$
matches only the exact string abc
Quantifiers
*
abc*
matches any string containing ab followed by any number of c s
+
abc+
matches any string containing ab followed by at least one c
?
abc?
matches any string containing ab followed by at the most one c
{n}
abc{2}
matches any string containing ab followed by two c s
abc{2,}
matches any string containing ab followed by two or more c s
abc{2,5}
matches any string containing ab followed by between two and five c s
OR operator
a|b
a or b
[abc]
a or b or c
Character classes
\d
\d
matches any character in a string that is a digit
\D
matches any character that isn’t a digit
\w
\w
matches any character in a string that is a word character
\W
matches any character that isn’t a word character
\s
\s
matches any whitespace character in a string
\S
matches any non-whitespace character
.
.
matches any character in a string