Regex Cheatsheet

Text

Quick reference for JS regex syntax, character classes, anchors, quantifiers and lookarounds, a handy cheat sheet for writing and debugging match patterns.

42 entries
Character classes
10
.Any char except newline
\dDigit 0-9
\DNon-digit
\wWord char
\WNon-word char
\sWhitespace
\SNon-whitespace
[abc]Match a, b, or c
[^abc]Not a, b, or c
[a-z]a through z range
Anchors
4
^Start of string
$End of string
\bWord boundary
\BNon word boundary
Quantifiers
8
*Zero or more
+One or more
?Zero or one
{n}Exactly n times
{n,}n or more
{n,m}Between n and m times
*?Lazy zero or more
+?Lazy one or more
Groups & lookarounds
8
(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind
\1Backreference to group 1
Flags
6
gGlobal
iCase insensitive
mMultiline
sDot matches newline
uUnicode mode
ySticky (y flag)
Common patterns
6
^\d{4}-\d{2}-\d{2}$ISO date
^[\w.+-]+@[\w-]+\.[\w.-]+$Simple email
^https?:\/\/\S+$HTTP URL
^\d{3}-\d{2}-\d{4}$US SSN
^#?([a-f\d]{6}|[a-f\d]{3})$Hex color
^\+?[1-9]\d{1,14}$E.164 phone

About Regex Cheatsheet

Writing regex always means recalling what \d, \w, quantifiers, and zero-width assertions mean, and flipping through docs is slow. This tool is a structured regular-expression cheat sheet that groups common syntax — character classes, quantifiers, anchors, groups, and assertions — by topic, with explanations and examples. Everything loads locally with the page and needs no network lookup, so you can reference it while coding and assemble the right pattern fast. For example, the built-in email-validation pattern works straight out of the box for form input checks.

How to Use

  1. Open the Regex Cheatsheet tool
  2. Paste the text to process
  3. Adjust the output options as needed
  4. Click the Process button; results appear in real time
  5. Copy or export the result

Use Cases

  • Recall syntax — Instantly look up .*? vs .+? when you forget how to write a non-greedy match.
  • Assertion lookup — Check lookahead and lookbehind syntax to match only in a specific context.
  • Class reference — Look up \d, \s, \b and avoid misusing \b inside a character set.
  • Interview prep — Systematically review regex syntax for written tests and technical interviews.
  • Teaching aid — Use the cheat sheet as a shared reference when explaining regex to newcomers.
  • Pattern debugging — Cross-reference a regex pattern's components against the cheat sheet to find the exact syntax error.
  • Migration reference — Update old PCRE patterns to ECMAScript-compatible syntax by checking the supported features per engine.

FAQ

Which regex flavor does the sheet target?

It centers on the most common syntax, close to JavaScript (ECMAScript); most rules also apply to PCRE and Python, with minor engine-specific differences.

Is \b consistent across languages?

The basic meaning of the word boundary \b is the same, but boundary detection for Unicode characters like CJK can differ between engines, so test it.

Can I test my regex here?

This page is a syntax reference; to verify matches as you type, use one of our regex tester tools for live debugging.

What is the difference between greedy and lazy?

A greedy quantifier like * matches as much as possible, while a lazy one like *? matches as little as possible; lazy is common for paired structures like HTML tags to avoid overshooting.

Why do I need two backslashes in a string?

In most languages a backslash must be escaped in string literals, so regex \d is often written as two backslashes plus d in code — mind the difference.

Advertisement