Skip to main content
>_laboratory.sh

Regex Cheat Sheet

Quick reference for regular expression syntax with search and filter.

Characters

.

Any character except newline

a.c matches abc, aXc

\d

Digit (0-9)

\d+ matches 123

\D

Non-digit

\D+ matches abc

\w

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

\w+ matches hello_1

\W

Non-word character

\W matches @, !

\s

Whitespace (space, tab, newline)

a\sb matches a b

\S

Non-whitespace

\S+ matches hello

[abc]

Character set — matches a, b, or c

[aeiou] matches vowels

[^abc]

Negated set — anything except a, b, c

[^0-9] matches non-digits

[a-z]

Character range

[A-Za-z] matches letters

Quantifiers

*

0 or more

ab*c matches ac, abc, abbc

+

1 or more

ab+c matches abc, abbc

?

0 or 1 (optional)

colou?r matches color, colour

{n}

Exactly n times

a{3} matches aaa

{n,}

n or more times

a{2,} matches aa, aaa

{n,m}

Between n and m times

a{2,4} matches aa, aaa, aaaa

*?

0 or more (lazy)

a.*?b matches ab in aXbYb

+?

1 or more (lazy)

a.+?b matches aXb in aXbYb

Groups

(abc)

Capturing group

(ha)+ matches haha

(?:abc)

Non-capturing group

(?:ha)+ matches haha

(?<name>abc)

Named capturing group

(?<year>\d{4})

\1

Back-reference to group 1

(\w)\1 matches aa, bb

(a|b)

Alternation — a or b

(cat|dog) matches cat or dog

Anchors

^

Start of string / line

^Hello matches Hello at start

$

End of string / line

world$ matches world at end

\b

Word boundary

\bcat\b matches cat, not catch

\B

Non-word boundary

\Bcat matches catch, not cat

Flags

g

Global — all matches

/a/g finds all a's

i

Case-insensitive

/hello/i matches Hello

m

Multiline — ^ and $ match per line

/^a/m matches a on each line

s

Dotall — . matches newline

/a.b/s matches a\nb

u

Unicode support

/\u{1F600}/u matches emoji

Lookahead / Lookbehind

(?=abc)

Positive lookahead

a(?=b) matches a in ab

(?!abc)

Negative lookahead

a(?!b) matches a in ac

(?<=abc)

Positive lookbehind

(?<=a)b matches b in ab

(?<!abc)

Negative lookbehind

(?<!a)b matches b in cb

How to Use Regex Cheat Sheet

Step 1

Browse categories like Characters, Quantifiers, Groups, and more.

Step 2

Use the search bar to filter patterns by keyword.

Step 3

Review the syntax, description, and example for each pattern.

Step 4

Use patterns directly in your code or regex tester.

Features

Comprehensive coverage of common regex patterns.

Organized into logical categories for easy browsing.

Instant search and filter across all patterns.

Each entry includes syntax, description, and example.

FAQ

A regular expression (regex) is a sequence of characters that defines a search pattern, commonly used for string matching, validation, and text manipulation.

This cheat sheet covers standard regex syntax supported by most languages including JavaScript, Python, Java, and others. Language-specific extensions are noted where applicable.

Yes. Use the search bar at the top to filter patterns by syntax, description, or example text.

The cheat sheet is a static reference with a search filter. For live regex testing, check out our Regex Tester tool.