Skip to content

Regex Cheat Sheet

JavaScript regex tokens, flags and tested-pattern examples.

By ToolzHive · Updated

These examples use JavaScript regex. Other engines differ. Test positive and negative cases, and avoid unbounded patterns on untrusted long input.

Download reference CSV

Reference table

Regex Cheat Sheet
TokenMeaningExample
\dDigit 0–9\d{4}
\wASCII word character, with case-folding exceptions\w+
\sWhitespace\s+
.Any character except line terminators unless s is enableda.b
^ / $Start / end assertions^cat$
[abc]One character in a set[aeiou]
[^abc]One character outside a set[^0-9]
* / + / ?Zero or more / one or more / optionalcolou?r
{n,m}Bounded repetition\d{2,4}
(…)Capturing group(red|blue)
(?:…)Non-capturing group(?:red|blue)
\bWord boundary\bcat\b
g / iGlobal / ignore case/cat/gi
m / sLine assertions / dot matches line terminators/a.b/s
uUnicode-aware mode/./u

Copyable example

const pattern = /^[A-Z]{2}-[0-9]{4}$/;
pattern.test("AB-1234"); // true

Worked example

^[A-Z]{2}-[0-9]{4}$ matches AB-1234. Test lowercase letters, spaces and missing digits. JavaScript $ can also match before a final line terminator.

Escaping

A regex literal /\d+/ and a RegExp string need different escaping: new RegExp("\\d+"). A short email pattern does not provide complete address validation.

Try the related tools

  • Regex Tester — Test regular expressions with live match highlighting and groups.

Sources

Related references

Browse all free resources

Accessibility Menu

Personalize your experience. Open with Ctrl+U (Option+U on Mac). Preferences stay in this browser when storage is available.

Move / Hide Widget

Restore at any time with Ctrl+U (Option+U on Mac).

Accessibility statement and help