Regex Cheatsheet

Regular expression syntax, patterns, and common examples.

Basic Patterns

.

Any character except newline

^

Start of string

$

End of string

\d

Any digit [0-9]

\D

Any non-digit

\w

Any word character [a-zA-Z0-9_]

\W

Any non-word character

\s

Any whitespace character

\S

Any non-whitespace character

Quantifiers

*

Zero or more times

+

One or more times

?

Zero or one time

{n}

Exactly n times

{n,}

At least n times

{n,m}

Between n and m times

Character Classes

[abc]

Any of a, b, or c

[^abc]

Not a, b, or c

[a-z]

Any lowercase letter

[A-Z]

Any uppercase letter

[0-9]

Any digit

Groups & Lookaround

(abc)

Capture group

(?:abc)

Non-capturing group

(?=abc)

Positive lookahead

(?!abc)

Negative lookahead

(?<=abc)

Positive lookbehind

(?<!abc)

Negative lookbehind