Regex & Text

Regex Cheat Sheet

Use this compact JavaScript regex reference to recall common tokens, then test the complete pattern against positive and negative examples.

Published

Interactive reference

Find a token, then test it

Choose Try in any row. One shared Regex Tester below receives the matching preset.

Character Classes

.Any character except a line terminator
\d / \DDigit / non-digit
\w / \WWord character / non-word character
\s / \SWhitespace / non-whitespace
[abc]One listed character
[^abc]One character not listed
[a-z]One lowercase ASCII letter

Anchors

^Start of input or line with m
$End of input or line with m
\bWord boundary

Quantifiers

*Zero or more
+One or more
?Zero or one
{n}Exactly n
{n,}At least n
{n,m}From n to m
*? / +?Lazy repetition

Groups

(abc)Capture a group
(?:abc)Group without capturing
a|bMatch either alternative
(?<name>abc)Named capture in the current JavaScript engine

Escaping

\.Literal dot
\*Literal asterisk
\?Literal question mark
\\Literal backslash

Flags

gFind every match
iIgnore case
mMake anchors line-aware
sLet dot match line terminators
uUnicode-aware parsing
ySticky matching from the current lastIndex

Shared Regex Lab

Start anchor

Test ^ in the shared JavaScript Regex Tester.

^

Expected result: Matches DEV only at a line start.

In JavaScript strings and JSON, a regex backslash needs an additional string-level escape.

Practice with the full tool

Test your own regex

Move from reference syntax to your real pattern, test text, flags and matches.

Continue in Regex Tester →