All tools

Regex Cheatsheet

Tokens, flags, and common patterns reference.

Tokens

.Any character (except newline)
\dDigit (0-9)
\DNon-digit
\wWord character (a-z, A-Z, 0-9, _)
\WNon-word character
\sWhitespace (space, tab, newline)
\SNon-whitespace
^Start of string (or line in multiline mode)
$End of string (or line)
\bWord boundary
\BNon-word boundary
*0 or more (greedy)
+1 or more (greedy)
?0 or 1, or makes a quantifier lazy
{n}Exactly n
{n,}n or more
{n,m}Between n and m
[abc]Any of a, b, or c
[^abc]Anything except a, b, or c
[a-z]Range a through z
(...)Capturing group
(?:...)Non-capturing group
(?=...)Positive lookahead
(?!...)Negative lookahead
(?<=...)Positive lookbehind
(?<!...)Negative lookbehind
a|ba or b
\1, \2Back-reference to capture group 1, 2

Flags

/gGlobal (find all matches)
/iCase-insensitive
/mMultiline (^ and $ match line breaks)
/sDotall (. matches newline)
/uUnicode
/ySticky (match from lastIndex)

Common patterns

Email (simple)[^\s@]+@[^\s@]+\.[^\s@]+
URLhttps?:\/\/[^\s]+
IPv4\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
Phone (US)\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}
Hex color#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})
Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}
UUID[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
Slug[a-z0-9]+(?:-[a-z0-9]+)*
Whitespace lines^\s*$
Trailing whitespace[ \t]+$

JavaScript flavor regex (POSIX flavor differs slightly). For the live tester, use the dedicated regex tester tool. For a deep dive, regular-expressions.info is the best free reference.

About

Quick reference for JavaScript regex: tokens (\d, \w, \b), quantifiers (*, +, ?), groups, lookarounds, and flags. Plus 10 ready-to-use patterns for email, URL, IPv4, etc.

How to use

  1. Skim the table for what you need.

FAQ

Are these patterns production-ready?+

The simple ones (URL, IPv4) work for 90%+ of cases. Email regex is famously hard - the simple version misses edge cases but covers what you'd actually find in user input.