Regex Cheat Sheet

Regex syntax reference

Character Classes

TokenDescription
\d
Any digit (0-9)
\D
Any non-digit character
\w
Word character: letter, digit, or underscore
\W
Any non-word character
\s
Any whitespace character (space, tab, newline)
\S
Any non-whitespace character
.
Any character except newline (unless the s flag is set)

Anchors

TokenDescription
^
Start of the string (or line, with the m flag)
$
End of the string (or line, with the m flag)
\b
A word boundary (edge between \w and \W)
\B
Not a word boundary

Quantifiers

TokenDescription
*
Zero or more of the preceding token
+
One or more of the preceding token
?
Zero or one of the preceding token (optional)
{n,m}
Between n and m repetitions of the preceding token

Groups

TokenDescription
()
Capturing group — remembers the matched text for later reference
(?:)
Non-capturing group — groups without saving the match
(?<name>)
Named capturing group, accessible by name in the match result

Lookaround

TokenDescription
(?=)
Positive lookahead — matches only if followed by this pattern
(?!)
Negative lookahead — matches only if NOT followed by this pattern
(?<=)
Positive lookbehind — matches only if preceded by this pattern
(?<!)
Negative lookbehind — matches only if NOT preceded by this pattern

Flags

TokenDescription
g
Global — find all matches instead of stopping at the first
i
Ignore case — match letters regardless of case
m
Multiline — ^ and $ match start/end of each line
s
Dot-all — . also matches newline characters
u
Unicode — treats the pattern as a sequence of Unicode code points
y
Sticky — matches only from the current position (lastIndex)

What Is This Tool?

The Regex Cheat Sheet is a quick reference for the most commonly used regular expression tokens: character classes, anchors, quantifiers, groups, lookaround assertions, and flags. Each row shows the token, a plain-English explanation, and a one-click Copy button so you can paste it straight into your own pattern.

How to Use

1

Scan the tables to find the token you need — grouped by category.

2

Read the plain-English description to confirm what it does.

3

Click Copy next to the token to copy it to your clipboard.

4

Paste it into your pattern in the Regex Tester or your own code.

Features

  • Organized by character classes, anchors, quantifiers, groups, lookaround, and flags
  • Plain-English description for every token
  • One-click copy for any token
  • Covers standard JavaScript (ECMAScript) regex syntax
  • 100% client-side — nothing leaves your browser

Examples

Match a word boundary followed by digits: \b\d+\b

Match an optional protocol before a domain: (https?:\/\/)?example\.com

Match text not followed by a specific word (negative lookahead): foo(?!bar)

Common Use Cases

  • Looking up an unfamiliar regex token while reading someone else's code
  • Refreshing your memory on lookahead/lookbehind syntax
  • Teaching or learning regular expressions
  • Quickly copying a token while building a pattern in the Regex Tester

Frequently Asked Questions

Which regex flavor does this cheat sheet cover?

It covers standard JavaScript (ECMAScript) regular expression syntax, the same flavor used by browsers and Node.js.

Does clicking Copy send anything to a server?

No. The Copy buttons use your browser's clipboard API directly. Nothing is uploaded or logged.

What is the difference between a capturing and non-capturing group?

A capturing group () saves its matched text so you can reference it later (for example, in a replacement string). A non-capturing group (?:) groups tokens together without saving the match, which is slightly more efficient when you don't need the value.

What's the difference between lookahead and lookbehind?

Lookahead (?=) or (?!) checks what comes after the current position without consuming it. Lookbehind (?<=) or (?<!) checks what comes before the current position, also without consuming it.

Why doesn't my pattern match multiple times?

By default, JavaScript regex stops after the first match. Add the g (global) flag to find every occurrence in the text.

Can I test these tokens directly?

Yes — copy any token and paste it into the Regex Tester to try it against your own text.