Regex Cheatsheet - Regular Expression Quick Reference

Quick reference for regular expression patterns. Character classes, quantifiers, anchors, and common patterns.

Share
.

Any single character except newline

Example: a.c → abc, aac

\d

Digit [0-9]

Example: \d+ → 123

\D

Non-digit

Example: \D+ → abc

\w

Word character

Example: \w+ → hello_world

\W

Non-word character

Example: \W+ → @#$

\s

Whitespace

Example: \s+ → " "

\S

Non-whitespace

Example: \S+ → hello

[abc]

Match a, b, or c

Example: [aeiou] → a

[^abc]

Not a, b, or c

Example: [^0-9] → a

[a-z]

Lowercase letter

Example: [a-z]+ → hello

[A-Z]

Uppercase letter

Example: [A-Z]+ → HELLO

[0-9]

Digit

Example: [0-9]+ → 123

[a-zA-Z]

Letter

Example: [a-zA-Z]+ → Hello

^

Start of line

Example: ^Hello → Hello world

$

End of line

Example: world$ → Hello world

\b

Word boundary

Example: \bcat\b → cat

\B

Non-word boundary

Example: \Bcat → category

*

Zero or more

Example: a* → "" or "aaa"

+

One or more

Example: a+ → "a" or "aaa"

?

Zero or one

Example: colou?r → color or colour

{n}

Exactly n times

Example: a{3} → aaa

{n,}

At least n times

Example: a{2,} → aa or aaa

{n,m}

Between n and m times

Example: a{2,4} → aa, aaa, aaaa

*?

Lazy zero or more

Example: <.*?> → <a>

+?

Lazy one or more

Example: <.+?> → <a>

(abc)

Capturing group

Example: (\d+)-\1 → 123-123

(?:abc)

Non-capturing group

Example: (?:abc)+ → abcabc

(?<name>abc)

Named capturing group

Example: (?<year>\d{4})

|

Alternation

Example: cat|dog → cat or dog

(?=abc)

Positive lookahead

Example: \w+(?=ing) → run in running

(?!abc)

Negative lookahead

Example: \w+(?!ing) → run in run

(?<=abc)

Positive lookbehind

Example: (?<=\$)\d+ → 100 in $100

(?<!abc)

Negative lookbehind

Example: (?<!\$)\d+ → 100 in €100

\\

Backslash

Example: C:\\Windows

\.

Literal dot

Example: \.com → .com

\*

Literal asterisk

Example: a\*b → a*b

\+

Literal plus

Example: a\+b → a+b

\?

Literal question mark

Example: a\?b → a?b

\[

Literal [

Example: \[abc\] → [abc]

\(

Literal (

Example: \(abc\) → (abc)

\^

Literal ^

Example: 2\^3 → 2^3

\$

Literal $

Example: \$100 → $100

\n

Newline

Example: line1\nline2

\t

Tab

Example: col1\tcol2

\r

Carriage return

Example: \r\n (Windows)

i

Case insensitive

Example: /hello/i → HELLO

g

Global match

Example: /a/g → all a's

m

Multiline

Example: /^a/m → a at line start

s

Dot matches newline

Example: /.+/s → includes \n

u

Unicode

Example: /\u{1F600}/u → 😀

y

Sticky

Example: /\d+/y → consecutive digits

^[\w-]+@[\w-]+\.[\w-]+$

Email address

Example: user@example.com

^https?://[^\s]+$

URL

Example: https://example.com

^\d{4}-\d{2}-\d{2}$

Date YYYY-MM-DD

Example: 2024-01-15

^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$

IP address

Example: 192.168.1.1

^\+?[\d\s-()]{7,}$

Phone number

Example: +86 138-0000-0000

^\d{6}$

6-digit code

Example: 123456

\b[\w-]+\b

Word

Example: hello-world

<[^>]+>

HTML tag

Example: <div class="test">

^\d+$

Digits only

Example: 12345

^[a-zA-Z]+$

Letters only

Example: Hello

^[a-zA-Z0-9_]+$

Word characters

Example: hello_world123

^\S+$

Non-whitespace

Example: no-spaces

\d{4}-\d{4}-\d{4}-\d{4}

Credit card

Example: 1234-5678-9012-3456

^#[0-9A-Fa-f]{6}$

Hex color

Example: #FF5733

^[A-Za-z0-9+/]{4}*[A-Za-z0-9+/]{2}==$

Base64 encoded

Example: SGVsbG8=

\b\d{1,3}(,\d{3})*(\.\d+)?\b

Number with commas

Example: 1,234,567.89

^[a-z]+(-[a-z]+)*$

Kebab-case

Example: hello-world-test

^[a-z]+(_[a-z]+)*$

Snake_case

Example: hello_world_test

^[A-Z][a-z]+([A-Z][a-z]+)*$

CamelCase

Example: HelloWorldTest

70 of 70 patterns shown

Related Tools

More Code & Dev Tools