Regex Tester Home/Guides & Research
Developer Tools
November 27, 2026•3 min read•Prinju Prasad

JavaScript Regex Cheat Sheet: Syntax, Flags and Examples

Regular expressions are compact but easy to forget. This reference covers the JavaScript syntax you will use most, with examples you can paste into a tester.

100% Client-Side Privacy: All calculators, converters, and processing run in your browser with zero data uploads.

Put this guide into practice with Regex Tester

Instant calculations with full formula breakdowns. No registration required.

Character classes

. any character except line breaks (unless the s flag is set) \d \D digit / not a digit \w \W word character [A-Za-z0-9_] / not \s \S whitespace / not [abc] a, b or c [^abc] anything except a, b, c [a-z] range

Quantifiers

* 0 or more + 1 or more ? 0 or 1 {3} exactly 3 {2,} 2 or more {2,5} between 2 and 5 *? +? ?? lazy versions (match as little as possible)

Anchors and boundaries

^ start of input (or line, with the m flag) $ end of input (or line, with the m flag) \b word boundary

Groups and references

(abc) capturing group, referenced as $1 in replacements (?:abc) non-capturing group (?<year>\d{4}) named group, referenced as $<year> \1 backreference to group 1 inside the pattern a|b alternation

Lookarounds

(?=...) followed by (?!...) not followed by (?<=...) preceded by (?<!...) not preceded by

Example: match a price number without the currency sign: (?<=\$)\d+(\.\d{2})?

Flags

g global (find all matches) i case-insensitive m multiline ^ and $ s dot matches line breaks u Unicode mode y sticky (match at lastIndex) d indices for matched groups

Replacement patterns

"2026-11-27".replace(/(\d+)-(\d+)-(\d+)/, "$3/$2/$1") // "27/11/2026" $& the whole match $1, $2 numbered groups $<name> named group

Avoid catastrophic backtracking

Patterns with nested quantifiers, such as (a+)+$ or (.*)*, can take an extremely long time on inputs that almost match. Prefer specific character classes, avoid nesting quantifiers, and test against long non-matching strings.

Experience Lightning-Fast, Private In-Browser Computing

Use Regex Tester directly in your browser. All algorithms adhere to verified mathematical formulas and industry-standard protocols.