{ } DevToolCore Free Online Developer Tools Tools Blog
Reference

Regular Expressions Cheat Sheet for Developers

2026-07-24 · 6 min read

Regular expressions are the Swiss Army knife of text processing. They are also notoriously hard to remember. This cheat sheet covers the syntax you will use 95% of the time, with examples you can test in your browser.

Character Classes

  • . — Any character except newline
  • \d — Digit (0-9)
  • \w — Word character (a-z, A-Z, 0-9, _)
  • \s — Whitespace (space, tab, newline)
  • [abc] — Any of a, b, or c
  • [^abc] — Anything except a, b, or c
  • [a-z] — Range: lowercase letters

Quantifiers

  • * — Zero or more
  • + — One or more
  • ? — Zero or one (also makes quantifiers lazy)
  • {n} — Exactly n times
  • {n,m} — Between n and m times

Anchors

  • ^ — Start of string (or line in multiline mode)
  • $ — End of string (or line in multiline mode)
  • \b — Word boundary

Groups and Capturing

  • (abc) — Capturing group
  • (?:abc) — Non-capturing group
  • (?<name>abc) — Named group
  • \1 — Back-reference to group 1

Lookarounds

  • (?=abc) — Positive lookahead: match only if followed by abc
  • (?!abc) — Negative lookahead: match only if NOT followed by abc
  • (?<=abc) — Positive lookbehind
  • (?<!abc) — Negative lookbehind

Real-World Examples

  • Email (simple): ^\w+@\w+\.\w+$
  • URL: https?://[^\s]+
  • Phone (US): ^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
  • Hex color: ^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
  • Slug: ^[a-z0-9]+(?:-[a-z0-9]+)*$

Flags

  • i — Case insensitive
  • g — Global (find all matches)
  • m — Multiline (^ and $ match line boundaries)
  • s — Dotall (. matches newline)

Test Your Patterns

Open the Regex Tester, paste a pattern, and type test text. Matches highlight in real time. Toggle flags with the checkboxes above the input.