Regex Cheat Sheet

Regular expressions describe text patterns. Try any pattern below in the regex tester. Syntax differs slightly between languages, and this sheet follows JavaScript.

Characters

PatternMatches
.Any character except a newline
\dA digit, 0 to 9
\wA letter, digit or underscore
\sA space, tab or newline
\D \W \SThe opposite of \d, \w, \s
[abc]One of a, b or c
[a-z]One lowercase letter
[^abc]Any character except a, b or c
\.A literal dot (escape special characters with a backslash)

Anchors

PatternMatches
^The start of the text (or line with the m flag)
$The end of the text (or line with the m flag)
\bA word boundary

Quantifiers

PatternMeaning
*Zero or more
+One or more
?Zero or one
{3}Exactly 3
{2,5}Between 2 and 5
{2,}2 or more
+? *?Lazy versions that match as little as possible

Groups and choices

PatternMeaning
(abc)Capturing group
(?:abc)Non-capturing group
(?<year>\d{4})Named group
a|ba or b
\1Repeats the first captured group

Lookarounds

PatternMeaning
a(?=b)a only if followed by b
a(?!b)a only if not followed by b
(?<=b)aa only if preceded by b
(?<!b)aa only if not preceded by b

Flags

g finds all matches, i ignores case, m makes ^ and $ work per line, s lets . match newlines and u enables full Unicode.

Common patterns

  • Indian PIN code: ^[1-9]\d{5}$
  • Simple email check: ^[^\s@]+@[^\s@]+\.[^\s@]+$
  • Date like 2026-11-02: ^\d{4}-\d{2}-\d{2}$
  • Hex colour: ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
  • Extra spaces: \s{2,}

An email regex can only check the shape of an address. The only real test is to send a message to it.

↑ ↓ navigateEnter openEsc close