What is a regex cheatsheet?
A regex cheatsheet is a quick reference guide that summarizes the most common regular expression syntax, tokens and operators.
It helps beginners learn regex faster and allows experienced developers to quickly look up rarely used constructs.
The most important regex tokens to know
Most regular expressions are built using a small set of tokens such as character classes, quantifiers, groups and anchors.
Learning symbols like \d, \w, *, +, ?, ^ and $ covers a large percentage of real-world regex use cases.
Character classes explained
Character classes define which characters are allowed at a specific position in a match.
Examples include digits, letters, whitespace characters and custom sets such as [A-Z] or [0-9].
Understanding regex quantifiers
Quantifiers control how many times a character, token or group can appear.
Common quantifiers include *, +, ?, {3} and {1,10}, each providing different matching behavior.
Groups, alternation and anchors
Groups allow multiple tokens to be treated as a single unit, while alternation provides OR logic inside a pattern.
Anchors such as ^ and $ define where a match must start or end within a string.
Regex syntax differences between languages
Most regex syntax is shared across JavaScript, PHP, Python and PCRE, but some advanced features differ.
Lookbehind assertions, Unicode property escapes and named groups may not behave identically across regex engines.
How to learn regex efficiently
The best way to learn regex is to combine a cheatsheet with interactive testing.
Experimenting with patterns and immediately seeing matches helps build intuition much faster than memorizing syntax alone.
Anchors and boundaries
^ matches the start of a string or line, depending on multiline mode.
$ matches the end of a string or line.
\b matches a word boundary.
^hello\b
Character classes
\d matches a digit. \w matches a word character. \s matches whitespace.
[A-Z] matches one uppercase ASCII letter. [^0-9] matches one non-digit.
[A-Za-z0-9_]+
Quantifiers
? means optional, * means zero or more, + means one or more.
{3} means exactly three, {2,5} means between two and five.
\d{2,4}
Groups and alternatives
(abc) captures a group. (?:abc) groups without capturing.
cat|dog matches either cat or dog.
(?:cat|dog)s?
Lookarounds
(?=...) is a positive lookahead. (?!...) is a negative lookahead.
Lookbehind support depends on the regex engine.
\w+(?=:)