Tool Hub

Regex Cheatsheet

Interactive reference for regex metacharacters ยท flags ยท classes

38 entries

meta
.

Any single character except newline

a.c โ†’ 'abc'

meta
\d

Digit (0-9)

\d+ โ†’ '123'

meta
\D

Non-digit

\D+ โ†’ 'abc'

meta
\w

Word char [A-Za-z0-9_]

\w+ โ†’ 'foo_1'

meta
\W

Non-word char

\W โ†’ '!'

meta
\s

Whitespace (space, tab, newline)

a\sb โ†’ 'a b'

meta
\S

Non-whitespace

\S+ โ†’ 'foo'

meta
\b

Word boundary

\bcat\b โ†’ 'cat'

meta
\B

Non-word boundary

\Bcat โ†’ 'concat'

quantifier
*

0 or more (greedy)

a* โ†’ '', 'aaa'

quantifier
+

1 or more (greedy)

a+ โ†’ 'aaa'

quantifier
?

0 or 1 (optional)

colou?r โ†’ 'color', 'colour'

quantifier
{n}

Exactly n times

\d{4} โ†’ '2025'

quantifier
{n,}

n or more times

\d{2,} โ†’ '12', '123'

quantifier
{n,m}

Between n and m times

\d{2,4} โ†’ '12', '1234'

quantifier
*?

0 or more (lazy)

<.*?> โ†’ '<a>', '<b>'

quantifier
+?

1 or more (lazy)

.+? โ†’ minimal match

class
[abc]

Any one of a, b, c

[aeiou] โ†’ vowels

class
[^abc]

None of a, b, c

[^0-9] โ†’ non-digit

class
[a-z]

Range a to z

[A-Za-z] โ†’ letters

class
[\d\s]

Combined classes

[\d\.] โ†’ digit or dot

anchor
^

Start of string (or line with /m)

^foo โ†’ starts with foo

anchor
$

End of string (or line with /m)

bar$ โ†’ ends with bar

group
(abc)

Capturing group

(\d+)-(\w+) โ†’ captures both

group
(?:abc)

Non-capturing group

(?:foo|bar)+

group
(?<name>abc)

Named capture group

(?<year>\d{4})

group
a|b

Alternation (or)

cat|dog โ†’ 'cat' or 'dog'

group
\1

Backreference to group 1

(\w)\1 โ†’ 'oo' in 'book'

lookaround
(?=abc)

Positive lookahead

\d(?=px) โ†’ '12' in '12px'

lookaround
(?!abc)

Negative lookahead

\d(?!px) โ†’ digit not followed by px

lookaround
(?<=abc)

Positive lookbehind

(?<=\$)\d+ โ†’ '100' in '$100'

lookaround
(?<!abc)

Negative lookbehind

(?<!\$)\d+ โ†’ digit not after $

flag
g

Global โ€” all matches

/foo/g

flag
i

Case-insensitive

/FOO/i โ†’ matches 'foo'

flag
m

Multiline โ€” ^/$ per line

/^line/m

flag
s

Dotall โ€” . matches newline

/a.b/s

flag
u

Unicode mode

/\u{1F600}/u

flag
y

Sticky โ€” match from lastIndex

/foo/y

Verify outputs before using in production. No warranty โ€” see Terms.