← Back to tools

Regex Cheat Sheet

Quick reference for regular expressions. Search any pattern or concept.

Regular expressions (regex) are one of the most powerful tools in a developer's toolkit, but they have a reputation for being cryptic. The key is to learn them in layers: start with literal characters, add character classes (\d, \w), then quantifiers (*, +, {n}), and finally groups and lookaheads.

The most common mistake is writing overly complex patterns when simple ones would work. For example, validating an email doesn't need a 500-character RFC-compliant regex — /^[^\s@]+@[^\s@]+\.[^\s@]+$/ covers 99.9% of real-world emails. Start simple, test with real data, and add complexity only when needed.

Performance matters for regex in production code. Catastrophic backtracking occurs when a pattern has nested quantifiers that can match the same input in exponentially many ways — like (a+)+ on a string of a's. Use atomic groups or possessive quantifiers when available, and always test your patterns against edge cases and long inputs.

This tool in other languages:

Français:
Aide-mémoire regex

Español:
Hoja de referencia regex

Deutsch:
Regex-Spickzettel

Português:
Folha de referência regex

日本語:
正規表現チートシート

中文:
正则表达式速查表

한국어:
정규식 치트 시트

العربية:
ورقة مرجعية للتعبيرات النمطية

Frequently asked questions

How do I use this regex cheat sheet?

Search by pattern or concept (e.g. email, lookahead, \d). Each entry shows the pattern, what it matches, and a live example. Use it as a quick reference while building patterns in the Regex Tester.

What are the most common regex character classes?

\d matches any digit, \w matches word characters (letters, digits, underscore), \s matches whitespace (space, tab, newline). Uppercase versions (\D, \W, \S) are the negations. [a-z] defines custom character ranges.

What is the difference between * and + in regex?

* matches the preceding element zero or more times. + matches it one or more times. So a* matches an empty string, aa, aaa... while a+ requires at least one a. Both are greedy by default — add ? to make them lazy.

What are lookahead and lookbehind in regex?

Lookahead (?=...) checks if something follows without consuming it. Negative lookahead (?!...) checks it doesn't follow. Lookbehind (?<=...) and negative lookbehind (?<!...) do the same backwards. Useful for validating passwords, finding words not preceded by something, etc.

How do I match a whole word in regex?

Use word boundaries: \bword\b matches word as a standalone word, not inside password or keyword. \b is a zero-width assertion that marks the position between a word character and a non-word character.