Bookmark this page
Press Ctrl+D (Windows) or Cmd+D (Mac) to bookmark this page.
🔎 Regex

Regex Cheat Sheet

A compact regex cheat sheet with common symbols, patterns and practical examples.

SymbolsEmail and URL patternsGroups and quantifiersFlags and examples

Core symbols

. = any char
\d = digit
\w = word char
\s = whitespace
^ start, $ end

Common patterns

^\S+@\S+\.\S+$   # email
https?://\S+        # URL
\b\d{3}-\d{3}-\d{4}\b  # US phone
^[A-Za-z0-9_]{3,16}$ # username

Groups and quantifiers

(abc)       # capture group
(?:abc)     # non-capturing group
\d+         # one or more digits
\d{2,4}     # between 2 and 4 digits

Flags

/pattern/i   # ignore case
/pattern/g   # global
/pattern/m   # multiline
/pattern/s   # dotall

Lookarounds and cleanup

(?=\d{4})   # lookahead
(?!test)     # negative lookahead
(?<=@)\w+   # lookbehind

text.replace(/\s+/g, " ").trim()

Replacement examples

const cleaned = text.replace(/\s+/g, " ").trim();
const emails = text.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g);
const numbers = text.match(/\d+/g);
✓ Copied!