DevToolsForYou

Regex Cheatsheet

A quick reference for regular expression syntax — anchors, character classes, quantifiers, groups, lookaheads, flags, and common real-world patterns.

Updated Apr 11, 2026
Try the Regex Tester

Sections

  1. Anchors
  2. Character Classes
  3. Quantifiers
  4. Groups & Alternation
  5. Lookahead & Lookbehind
  6. Escapes & Special Characters
  7. Flags
  8. Common Patterns

Anchors

TokenDescription
^Start of string (or line in multiline mode)
$End of string (or line in multiline mode)
\bWord boundary
\BNot a word boundary
\AStart of string (no multiline)
\ZEnd of string (no multiline)

Character Classes

TokenDescription
.Any character except newline
\wWord character: [a-zA-Z0-9_]
\WNon-word character
\dDigit: [0-9]
\DNon-digit
\sWhitespace (space, tab, newline, etc.)
\SNon-whitespace
[abc]Character set — matches a, b, or c
[^abc]Negated character set — matches anything except a, b, or c
[a-z]Character range — matches any lowercase letter
[a-zA-Z0-9]Multiple ranges — alphanumeric

Quantifiers

TokenDescription
*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (greedy)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?0 or more (lazy — matches as few as possible)
+?1 or more (lazy)
??0 or 1 (lazy)

Groups & Alternation

TokenDescription
(abc)Capturing group — captures match as group 1, 2, …
(?:abc)Non-capturing group — groups without capturing
(?<name>abc)Named capturing group — accessible as group 'name'
a|bAlternation — matches a or b
\1Backreference to group 1
\k<name>Backreference to named group 'name'

Lookahead & Lookbehind

TokenDescription
(?=abc)Positive lookahead — asserts what follows matches abc
(?!abc)Negative lookahead — asserts what follows does NOT match abc
(?<=abc)Positive lookbehind — asserts what precedes matches abc
(?<!abc)Negative lookbehind — asserts what precedes does NOT match abc

Escapes & Special Characters

TokenDescription
\nNewline
\tTab
\rCarriage return
\0Null character
\uFFFFUnicode character by code point
\.Literal dot (escape reserved characters with \)

Flags

FlagDescription
gGlobal — find all matches, not just the first
iCase-insensitive — treats A and a as equivalent
mMultiline — ^ and $ match start/end of each line
sDot-all (dotAll) — makes . match newline characters too
uUnicode — enables full Unicode matching and escape sequences
ySticky — match only at the current position in the string

Common Patterns

Use CasePattern
Email address[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}
URL (http/https)https?:\/\/[^\s/$.?#].[^\s]*
IPv4 address\b(?:\d{1,3}\.){3}\d{1,3}\b
Hex colour code#(?:[0-9a-fA-F]{3}){1,2}\b
Date (YYYY-MM-DD)\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
Integer (positive)\b[1-9]\d*\b
Decimal number-?\d+(?:\.\d+)?
Slug (URL-safe)[a-z0-9]+(?:-[a-z0-9]+)*
UUID v4[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
JWT token[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+
HTML tag<([a-z][a-z0-9]*)(?:\s[^>]*)?>
Whitespace (trim)^\s+|\s+$
Related guidesAll guides →