Regex

Regex Cheat Sheet

Common regular-expression tokens and examples. Test patterns safely in the FreeToolMate regex tester — matching stays in your browser.

Quick tokens

  • . — any character except newline
  • \d — digit · \w — word character · \s — whitespace
  • ^ / $ — start / end of string
  • * · + · ? — zero-or-more · one-or-more · optional
  • [abc] — character class · [^abc] — negated
  • (...) — capturing group · (?:...) — non-capturing
  • a|b — alternation

Examples

  • Email-ish: ^[^@\s]+@[^@\s]+\.[^@\s]+$
  • Digits only: ^\d+$
  • Hex color: ^#?[0-9a-fA-F]{6}$
  • ISO date: ^\d{4}-\d{2}-\d{2}$

Try it

Open the Regex Tester to highlight matches against any string. Invalid or huge patterns are rejected so a bad expression cannot freeze the tab for long.

All articles · Developer Tools