UtilX

Regex Cheat Sheet: Syntax You Actually Use

Regular expressions have a huge spec, but 90% of real-world usage comes from about 20 tokens. Here they are.

Character classes

TokenMatches
.Any character except newline
\dAny digit (0-9)
\DAny non-digit
\wWord character (letters, digits, underscore)
\sWhitespace (space, tab, newline)
[abc]Any of a, b, or c
[^abc]Anything except a, b, or c
[a-z]Any lowercase letter, a through z

Quantifiers

TokenMeaning
*Zero or more
+One or more
?Zero or one (optional)
{n}Exactly n times
{n,m}Between n and m times

Anchors and boundaries

TokenMeaning
^Start of string (or line, with the m flag)
$End of string (or line, with the m flag)
\bWord boundary

Groups and lookarounds

TokenMeaning
(abc)Capture group
(?:abc)Non-capturing group
a|bMatch a or b
(?=abc)Positive lookahead — must be followed by "abc"
(?!abc)Negative lookahead — must not be followed by "abc"

Example: matching an email-like string

\b[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}\b

This is fine for quick filtering, but note that a fully RFC-compliant email regex is notoriously complex — for real validation, send a confirmation email instead of relying purely on regex.

Try it yourself

Paste any pattern into the Regex Tester to see live matches highlighted against your own sample text.