Buy Me A CoffeeRegexLearn - Learn Regex step by step, from zero to advanced | Product Hunt

Regex Cheatsheet

Explore all Regex patterns and symbols with the Regex cheatsheet.

Anchors

Matches the beginning of the string or line.

an answer or a question
^\w+

Matches the end of the string or line.

an answer or a question
\w+$

Matches the word character or position at the end of a word.

an answer or a question
n\b

Matches a word character or position that is not at the end of a word.

an answer or a question
n\B

Flags

Makes the expression case insensitive.

CaT
cat

Ensures that the expression does not stop on the first match.

cat cat cat
cat

If not enabled, line start and end equals the beginning and end of the entire string. It doesn't work for each row individually.

cat
cat
cat

Group & References

Groups an expression.

hahaha hah haha
(ha)+

References a grouped expression.

hah haa dad
(\w)a\1

Makes a grouping that cannot be referenced.

hahaha hah haha
(?:ha)+

Character Classes

Matches any character in the set.

bar ber bir bor bur
b[eo]r

Matches any character not in the set.

bar ber bir bor bur
b[^eo]r

Matches all characters between two characters, including themselves.

abcdefghijklmnopqrstuvwxyz
[e-i]

Matches any character except line breaks.

hi 012 _-!?
.

Matches any alphanumeric character. Including the underline.

hi 012 _-!?
\w

Matches any non-alphanumeric character.

hi 012 _-!?
\W

Matches any numeric character.

+1-(444)-222
\d

Matches any non-numeric character.

+1-(444)-222
\D

Matches any whitespace character.

one two
\s

Matches any non-whitespace character.

one two
\S

Lookarounds

1st 2nd 3pc
\d(?=nd)
1st 2nd 3pc
\d(?!nd)
#1 $2 %3
(?<=%)\d
#1 $2 %3
(?<!%)\d

Quantifiers And Alternation

Expression matches one or more.

bp bep beep beeep
be+p

Expression matches zero or more.

bp bep beep beeep
be*p

Expression matches within specified ranges.

bp bep beep beeep
be{1,2}p

Makes the expression optional.

color, colour
colou?r

Or it works like. It waits for one of the expressions it reserved to match.

fat, cat, rat
(c|r)at