Toolspark

Regex Cheatsheet

Complete interactive regular expression reference with live testing. Character classes, quantifiers, groups, lookaheads, and common patterns.

Share:𝕏fin↗
/.*+?/g

Live Regex Tester

//

Character Classes

.

Any character except newline

a.c → "abc", "a1c", "a-c"

📋
\d

Any digit (0-9)

\d{3} → "123", "456"

📋
\D

Any non-digit

\D+ → "abc", "hello"

📋
\w

Word character (a-z, A-Z, 0-9, _)

\w+ → "hello_42"

📋
\W

Non-word character

\W → "!", "@", " "

📋
\s

Whitespace (space, tab, newline)

a\sb → "a b", "a\tb"

📋
\S

Non-whitespace

\S+ → "hello", "42"

📋
[abc]

Any of a, b, or c

[aeiou] → "a", "e", "i"

📋
[^abc]

Not a, b, or c

[^0-9] → "a", "!"

📋
[a-z]

Range: a to z

[A-Za-z] → "a", "Z"

📋

Quantifiers

*

Zero or more

ab*c → "ac", "abc", "abbc"

📋
+

One or more

ab+c → "abc", "abbc" (not "ac")

📋
?

Zero or one

colou?r → "color", "colour"

📋
{n}

Exactly n times

\d{4} → "2024", "1234"

📋
{n,}

n or more times

\d{2,} → "12", "123", "1234"

📋
{n,m}

Between n and m times

\d{2,4} → "12", "123", "1234"

📋
*?

Zero or more (lazy)

<.*?> → "<b>" (not "<b>text</b>")

📋
+?

One or more (lazy)

\w+? → First character only

📋

Anchors & Boundaries

^

Start of string/line

^Hello → "Hello world" (start)

📋
$

End of string/line

world$ → "Hello world" (end)

📋
\b

Word boundary

\bcat\b → "cat" (not "catch")

📋
\B

Non-word boundary

\Bcat\B → "concatenate" (inner)

📋

Groups & References

(abc)

Capturing group

(\d{3})-(\d{4}) → "123-4567"

📋
(?:abc)

Non-capturing group

(?:ab)+ → "abab"

📋
(?<name>)

Named group

(?<year>\d{4}) → "2024"

📋
\1

Back-reference to group 1

(\w)\1 → "aa", "bb"

📋
(a|b)

Alternation (or)

(cat|dog) → "cat" or "dog"

📋

Lookahead & Lookbehind

(?=abc)

Positive lookahead

\d(?=px) → "5" in "5px"

📋
(?!abc)

Negative lookahead

\d(?!px) → "5" in "5em"

📋
(?<=abc)

Positive lookbehind

(?<=\$)\d+ → "50" in "$50"

📋
(?<!abc)

Negative lookbehind

(?<!\$)\d+ → "50" in "50"

📋

Flags

g

Global - match all occurrences

/cat/g → All "cat" matches

📋
i

Case-insensitive

/hello/i → "Hello", "HELLO"

📋
m

Multiline - ^ and $ match per line

/^start/m → Start of each line

📋
s

Dotall - . matches newlines

/a.b/s → "a\nb"

📋

Common Patterns

Email

Basic email validation

[\w.-]+@[\w.-]+\.\w{2,} → "user@site.com"

📋
URL

Basic URL matching

https?://[\w./%-]+ → "https://site.com/path"

📋
IP Address

IPv4 address

\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} → "192.168.1.1"

📋
Phone

US phone number

\d{3}[-.\s]?\d{3}[-.\s]?\d{4} → "555-123-4567"

📋
Hex Color

CSS hex color

#[0-9a-fA-F]{3,6} → "#fff", "#FF0000"

📋
Date

YYYY-MM-DD format

\d{4}-\d{2}-\d{2} → "2024-01-15"

📋

Frequently Asked Questions

Related Tools