Regex Cheatsheet
Interactive reference for regex metacharacters ยท flags ยท classes
38 entries
.Any single character except newline
a.c โ 'abc'
\dDigit (0-9)
\d+ โ '123'
\DNon-digit
\D+ โ 'abc'
\wWord char [A-Za-z0-9_]
\w+ โ 'foo_1'
\WNon-word char
\W โ '!'
\sWhitespace (space, tab, newline)
a\sb โ 'a b'
\SNon-whitespace
\S+ โ 'foo'
\bWord boundary
\bcat\b โ 'cat'
\BNon-word boundary
\Bcat โ 'concat'
*0 or more (greedy)
a* โ '', 'aaa'
+1 or more (greedy)
a+ โ 'aaa'
?0 or 1 (optional)
colou?r โ 'color', 'colour'
{n}Exactly n times
\d{4} โ '2025'
{n,}n or more times
\d{2,} โ '12', '123'
{n,m}Between n and m times
\d{2,4} โ '12', '1234'
*?0 or more (lazy)
<.*?> โ '<a>', '<b>'
+?1 or more (lazy)
.+? โ minimal match
[abc]Any one of a, b, c
[aeiou] โ vowels
[^abc]None of a, b, c
[^0-9] โ non-digit
[a-z]Range a to z
[A-Za-z] โ letters
[\d\s]Combined classes
[\d\.] โ digit or dot
^Start of string (or line with /m)
^foo โ starts with foo
$End of string (or line with /m)
bar$ โ ends with bar
(abc)Capturing group
(\d+)-(\w+) โ captures both
(?:abc)Non-capturing group
(?:foo|bar)+
(?<name>abc)Named capture group
(?<year>\d{4})
a|bAlternation (or)
cat|dog โ 'cat' or 'dog'
\1Backreference to group 1
(\w)\1 โ 'oo' in 'book'
(?=abc)Positive lookahead
\d(?=px) โ '12' in '12px'
(?!abc)Negative lookahead
\d(?!px) โ digit not followed by px
(?<=abc)Positive lookbehind
(?<=\$)\d+ โ '100' in '$100'
(?<!abc)Negative lookbehind
(?<!\$)\d+ โ digit not after $
gGlobal โ all matches
/foo/g
iCase-insensitive
/FOO/i โ matches 'foo'
mMultiline โ ^/$ per line
/^line/m
sDotall โ . matches newline
/a.b/s
uUnicode mode
/\u{1F600}/u
ySticky โ match from lastIndex
/foo/y
Verify outputs before using in production. No warranty โ see Terms.