Advertisement

Regex Cheat Sheet

A searchable regex cheat sheet plus a live tester. Look up any token, then try your pattern against sample text with matches highlighted in real time. Free, no sign-up.

Live regex tester

Type a pattern and test string. Matches highlight as you type.

g global, i case-insensitive, m multiline, s dot-all, u unicode

0 matches

Cheat sheet
Advertisement

How to use it

Type a regular expression in the pattern box and paste sample text below. Matches highlight in yellow as you type, with a live match count and plain-English error messages when the pattern is invalid.

Stuck on syntax? Search the cheat sheet on the right for any token, flag or recipe, grouped into basics, character classes, quantifiers, anchors, groups, lookaround, escapes and flags.

A practical approach to regex

Build patterns from small pieces and test each piece: start with what a valid match looks like, add anchors ^ and $ when the whole string must match, and prefer specific classes like \d over the greedy .*.

Remember the tester uses JavaScript regex flavor, which matches what runs in browsers and Node.js.

Regex Cheat Sheet FAQs

Why is my pattern showing an error?
The tester shows the JavaScript engine's exact error message. Common causes are unbalanced parentheses or brackets, a stray backslash at the end, or a lookbehind in an older browser that does not support it.
What does the g flag do?
Without g, only the first match is found. With g for global, the tester finds and highlights every match in the text, which is what you usually want when testing.
How do I match a literal dot or parenthesis?
Escape it with a backslash: \. for a dot, \( and \) for parentheses. Unescaped, . means any character and ( ) starts a group.
What is the difference between * and +?
Both repeat the previous token: * allows zero or more (the token may be absent), + requires one or more. Add ? after either, like +?, to make it lazy and match as little as possible.
Is my test data uploaded?
No. The pattern compiles and runs in your browser's own regex engine. Nothing you type leaves your device.
Advertisement