coderef

Regex Quick Reference

Regular expressions: character classes, anchors, quantifiers, groups, lookarounds, flags and ready-made patterns.

7 sections · 44 snippets · updated Oct 14, 2026

Click any snippet to copy it.

Characters

What to match.

  • Any character except newline
  • Digit / not a digit
  • Word character / not
  • Whitespace / not
  • One of these characters
  • Not one of these
  • A range
  • Escape a special character

Anchors

Where to match.

  • Start / end of string
  • Start / end of each line
  • Word boundary

Quantifiers

How many times.

  • Zero or more
  • One or more
  • Optional
  • Exactly n
  • n or more / between n and m
  • As few as possible (lazy)

Groups & lookarounds

Capture and assert.

  • Capture group
  • Named group
  • Group without capturing
  • Either / or
  • Repeat a captured group
  • Followed by / not followed by
  • Preceded by / not preceded by

Flags

Change how the pattern matches.

  • Find all matches
  • Ignore case
  • ^ and $ per line
  • Dot matches newline
  • Unicode

Common patterns

Starting points — adjust to your needs.

  • Email (simple)
  • URL
  • Date (YYYY-MM-DD)
  • Time (24h HH:MM)
  • Hex color
  • IPv4 address
  • Strong password (8+, upper, lower, digit)
  • Slug
  • Whitespace at either end

Using regex in JavaScript

Apply patterns in code.

  • Test for a match
  • Get the first match
  • All matches with groups
  • Replace with groups
  • Split on a pattern
  • Build from a string

← All quick references