Regex Cheatsheet

Runs locally

A quick reference of regex character classes, quantifiers, anchors, groups and flags

Character classes

.

Any single character except newline

a.c → abc
\d

A single digit

\d{3} → 123
\w

Letter, digit or underscore

\w+ → abc_1
\s

Any whitespace character

a\sb → a b
[abc]

Any one character in the set

[aeiou] → e
[^abc]

Any character not in the set

[^0-9] → a
[a-z]

Any character in the range

[A-F] → C

Quantifiers

*

Zero or more times

ab* → abbb
+

One or more times

ab+ → abbb
?

Zero or one time

colou?r → color
{n,m}

Between n and m times

\d{2,4} → 2024
*?

Lazy match, as few as possible

<.*?> → <b>

Anchors and boundaries

^

Start of the string

^Hello
$

End of the string

world$
\b

Word boundary

\bword\b

Groups and lookaround

( )

Numbered capturing group

(\d+)-(\d+)
(?: )

Group without capturing

(?:ab)+
(?<name> )

Named capturing group

(?<year>\d{4})
a|b

Match either alternative

cat|dog
(?= )

Positive lookahead

\d(?=px)

Flags

g

Match all occurrences

/a/g
i

Case-insensitive matching

/abc/i
m

Multi-line mode

/^a/m
s

Let the dot match newlines

/a.b/s

How to use

  1. 1

    Paste or type the content you want to process

  2. 2

    Pick your options (indent size, key sorting and more)

  3. 3

    Check the result and copy it in one click

Privacy

Everything is processed locally in your browser and never uploaded to any server.