Regex Reference

Regex reference cheatsheet.

Every regex token worth remembering — character classes, anchors, quantifiers and lookaround — explained plainly.

Character classes
.Any character except newline
\\dA digit (0–9)
\\DA non-digit
\\wA word character (letter, digit or _)
\\WA non-word character
\\sAny whitespace
[abc]Any one of a, b or c
[^abc]Anything except a, b or c
[a-z]Any character in the range a to z
Anchors & boundaries
^Start of the string (or line with m flag)
$End of the string (or line with m flag)
\\bA word boundary
\\BNot a word boundary
Quantifiers
*Zero or more
+One or more
?Zero or one (optional)
{3}Exactly three
{2,}Two or more
{2,5}Between two and five
+?Lazy — match as few as possible
Groups & lookaround
(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture group
a|bMatch a or b
(?=abc)Lookahead — followed by abc
(?!abc)Negative lookahead
(?<=abc)Lookbehind — preceded by abc
Want to try these out? Paste a pattern into the live regex tester to see matches highlight as you type.

A map of the symbols

Regular expressions pack a lot of meaning into a few symbols, and most of the difficulty is simply remembering what each one does. This reference groups them the way you actually think about a pattern: character classes for "what kind of character" (\\d, \\w, [a-z]), anchors for position (^, $, \\b), quantifiers for "how many" (*, +, {2,5}), and groups and lookaround for structure and conditions.

From reference to working pattern

Reading tokens only gets you so far — regex really clicks when you watch one run against real text. Once you've found the pieces you need here, drop your pattern into the regex tester to see exactly what it matches and which capture groups it pulls out. Build up gradually, testing as you go, and even intimidating patterns become manageable.

FAQ

What's the difference between \\d and \\w?
\\d matches a single digit (0–9), while \\w matches any word character — a letter, a digit, or an underscore.
What does a question mark do in regex?
After a token it means 'optional' (zero or one). After another quantifier, like +?, it makes the match lazy — matching as few characters as possible.

More cheatsheets