DD
DevDash

Last updated: April 12, 2026

Regex Syntax Cheatsheet

Quick Answer

This cheatsheet covers essential regex syntax: character classes, quantifiers, anchors, groups, and lookaround assertions. Use it as a quick reference when writing regular expressions in any language.

Characters

CommandDescription
.

Match any single character (except newline by default)

a.c matches "abc", "a1c", "a-c"
\d

Match any digit (0-9)

\d{3} matches "123"
\w

Match any word character (letter, digit, underscore)

\w+ matches "hello_123"
\s

Match any whitespace (space, tab, newline)

hello\sworld matches "hello world"
\D, \W, \S

Negated versions: non-digit, non-word, non-whitespace

Character Classes

CommandDescription
[abc]

Match any one character in the set

[aeiou] matches any vowel
[^abc]

Match any character NOT in the set

[^0-9] matches non-digits
[a-z]

Match any character in the range

[A-Za-z] matches any letter

Anchors

CommandDescription
^

Match start of string (or line in multiline mode)

^Hello matches "Hello world"
$

Match end of string (or line in multiline mode)

world$ matches "hello world"
\b

Match word boundary

\bcat\b matches "cat" but not "category"

Quantifiers

CommandDescription
*

Match 0 or more of the preceding element (greedy)

ab*c matches "ac", "abc", "abbc"
+

Match 1 or more of the preceding element (greedy)

ab+c matches "abc", "abbc" but not "ac"
?

Match 0 or 1 of the preceding element (optional)

colou?r matches "color" and "colour"
{n}

Match exactly n occurrences

\d{4} matches "2026"
{n,m}

Match between n and m occurrences

\d{2,4} matches "12", "123", "1234"
*?, +?, ??

Lazy (non-greedy) versions — match as few as possible

<.+?> matches "<b>" not "<b>text</b>"

Groups

CommandDescription
(abc)

Capturing group — matches and captures "abc"

(\d{3})-(\d{4}) captures area and number
(?:abc)

Non-capturing group — matches but does not capture

(?:https?://) matches protocol without capturing
(?<name>abc)

Named capturing group

(?<year>\d{4}) captures as "year"
a|b

Alternation — match a OR b

cat|dog matches "cat" or "dog"

Lookaround

CommandDescription
(?=abc)

Positive lookahead — match if followed by abc

\d+(?=px) matches "12" in "12px"
(?!abc)

Negative lookahead — match if NOT followed by abc

\d+(?!px) matches "12" in "12em"
(?<=abc)

Positive lookbehind — match if preceded by abc

(?<=\$)\d+ matches "50" in "$50"
(?<!abc)

Negative lookbehind — match if NOT preceded by abc

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

Frequently Asked Questions

More Cheatsheets

Want API access + no ads? Pro coming soon.