Regex Cheatsheet

Searchable regex syntax reference with examples and copy buttons.

Works Offline
Privacy First
No Login
No API

Basics

  • .

    Any character except newline

    a.c matches abc

Character classes

  • \d

    Any digit (0-9)

    \d+ matches 123

  • \D

    Any non-digit

    \D+ matches abc

  • \w

    Word character (letter, digit, underscore)

    \w+ matches hello_1

  • \W

    Non-word character

    \W matches !

  • \s

    Whitespace character

    a\sb matches 'a b'

  • \S

    Non-whitespace character

    \S+ matches abc

  • [abc]

    Any of a, b, or c

    [abc]+ matches cab

  • [^abc]

    Any character except a, b, c

    [^abc] matches d

  • [a-z]

    Any lowercase letter

    [a-z]+ matches hello

Anchors

  • ^

    Start of string/line

    ^Hello matches 'Hello world'

  • $

    End of string/line

    world$ matches 'Hello world'

  • \b

    Word boundary

    \bcat\b matches 'a cat sat'

  • \B

    Non-word boundary

    \Bcat matches 'concatenate'

Quantifiers

  • *

    0 or more of the previous token

    ab*c matches ac, abc, abbc

  • +

    1 or more of the previous token

    ab+c matches abc, abbc

  • ?

    0 or 1 of the previous token (optional)

    colou?r matches color, colour

  • {n}

    Exactly n repetitions

    \d{3} matches 123

  • {n,}

    n or more repetitions

    \d{2,} matches 12, 123

  • {n,m}

    Between n and m repetitions

    \d{2,4} matches 12, 123, 1234

  • *?

    Lazy (non-greedy) 0 or more

    <.*?> matches '<a>' first, not '<a><b>'

Groups

  • (abc)

    Capturing group

    (ab)+ captures repeated 'ab'

  • (?:abc)

    Non-capturing group

    (?:ab)+ groups without capturing

  • (?<name>abc)

    Named capturing group

    (?<year>\d{4})

  • a|b

    Alternation — a or b

    cat|dog matches cat or dog

Lookaround

  • (?=abc)

    Positive lookahead

    \d(?=px) matches digit before 'px'

  • (?!abc)

    Negative lookahead

    \d(?!px) matches digit not before 'px'

  • (?<=abc)

    Positive lookbehind

    (?<=\$)\d+ matches digits after $

  • (?<!abc)

    Negative lookbehind

    (?<!\$)\d+ matches digits not after $

Flags

  • g

    Global flag — find all matches

    /a/g

  • i

    Case-insensitive flag

    /abc/i matches ABC

  • m

    Multiline flag — ^ and $ match line boundaries

    /^a/m

  • s

    Dotall flag — . matches newlines too

    /a.b/s

  • u

    Unicode flag

    /\u{1F600}/u

Basics
Character classes
Anchors
Quantifiers
Groups
Lookaround
Flags

About the Regex Cheatsheet

Browse a categorized, searchable reference of regular expression syntax — character classes, anchors, quantifiers, groups, lookaround, and flags — each with an example and a copy button.

Examples

Lookahead

lookahead

Output

(?=abc) — positive lookahead

Related tools

Frequently asked questions

Read more

Version 1.0.0 · Updated 2026-08-06 · Runs entirely in your browser