RegexLearn
LearnCheatsheetPlaygroundGitHub
Coming Soon

Anchors

^
Start of string or line

Matches the beginning of the string or line.

an answer or a question
^\w+
$
End of string or line

Matches the end of the string or line.

an answer or a question
\w+$
\b
Word Boundary

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

an answer or a question
n\b
\B
Not Word Boundary

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

an answer or a question
n\B

Flags

i
Ignore Case

Makes the expression case insensitive.

CaT
cat
g
Global

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

cat cat cat
cat
m
Multiline

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

()
Group

Groups an expression.

hahaha hah haha
(ha)+
\1
Reference

References a grouped expression.

hah haa dad
(\w)a\1
(?:)
Non Capturing Group

Makes a grouping that cannot be referenced.

hahaha hah haha
(?:ha)+

Character Classes

[abc]
Character Set

Matches any character in the set.

bar ber bir bor bur
b[eo]r
[^abc]
Negated Character Set

Matches any character not in the set.

bar ber bir bor bur
b[^eo]r
[a-z]
Range

Matches all characters between two characters, including themselves.

abcdefghijklmnopqrstuvwxyz
[e-i]
.
Dot

Matches any character except line breaks.

hi 012 _-!?
.
\w
Word

Matches any alphanumeric character. Including the underline.

hi 012 _-!?
\w
\W
Not Word

Matches any non-alphanumeric character.

hi 012 _-!?
\W
\d
Digit

Matches any numeric character.

+1-(444)-222
\d
\D
Not Digit

Matches any non-numeric character.

+1-(444)-222
\D
\s
Whitespace

Matches any whitespace character.

one two
\s
\S
Not Whitespace

Matches any non-whitespace character.

one two
\S

Lookarounds

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

Quantifiers And Alternation

+
Plus

Expression matches one or more.

bp bep beep beeep
be+p
*
Asterisk

Expression matches zero or more.

bp bep beep beeep
be*p
{1,3}
Quantifier

Expression matches within specified ranges.

bp bep beep beeep
be{1,2}p
?
Optional

Makes the expression optional.

color, colour
colou?r
|
Alternation

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

fat, cat, rat
(c|r)at