Regex cheatsheet

Javascript Regex/Regular Expression cheatsheet

About Regex cheatsheet

A compact reference for JavaScript regular expressions: character classes, anchors, quantifiers, groups and backreferences, lookaround, flags and the escape sequences, with the meaning of each token.

When you would use it

How to use it

  1. Find the section for the construct you need.
  2. Read the token and its meaning, then try it in the Regex Tester tool.
  3. Use your browser's search (Ctrl+F) for a specific token.

Things worth knowing

Frequently asked questions

What is the difference between .* and .*?
.* is greedy and takes as much as possible, then backs off; .*? is lazy and takes as little as possible. On <b>a</b><b>b</b>, <b>.*</b> matches everything while <b>.*?</b> matches the first tag pair only.
Why does \d not match Arabic-Indic or other digits?
In JavaScript \d is always [0-9]. To match digits in other scripts use \p{Nd} with the u flag.

All the tools