Command Palette

Search for a developer tool

reference7 min read

Regex Tester & Cheatsheet — Test Regular Expressions Online

A practical reference for regular expressions: common patterns, flags, lookaheads, and how to test and debug regex online.

Regular expressions (regex) are one of the most powerful — and notoriously cryptic — tools in a developer's toolkit. A single well-crafted regex can replace dozens of lines of string manipulation code.

Test Regex Online

Use the Regex Tester to write and test patterns interactively:

  • Matches highlight in real time as you type
  • See all match groups and captured values
  • Test against multiple lines or a full block of text
  • Switch flags (global, case-insensitive, multiline) instantly

Regex Flags

FlagMeaning
gGlobal — find all matches, not just the first
iCase-insensitive matching
mMultiline — ^ and $ match start/end of each line
sDot-all — . matches newlines too
uUnicode mode — enables full Unicode support

Essential Patterns Cheatsheet

Character Classes

  • \d — digit (0–9)
  • \w — word character (a–z, A–Z, 0–9, _)
  • \s — whitespace (space, tab, newline)
  • [a-z] — character range
  • [^abc] — negated class (not a, b, or c)

Quantifiers

  • * — 0 or more
  • + — 1 or more
  • ? — 0 or 1 (optional)
  • {3} — exactly 3
  • {2,5} — between 2 and 5

Anchors & Boundaries

  • ^ — start of string (or line with m flag)
  • $ — end of string (or line with m flag)
  • \b — word boundary

Common Patterns

  • Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • URL: https?:\/\/[^\s]+
  • IPv4: (\d{1,3}\.){3}\d{1,3}
  • Hex color: #([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b
  • ISO date: \d{4}-\d{2}-\d{2}

Lookahead & Lookbehind

  • (?=...) — positive lookahead: match if followed by
  • (?!...) — negative lookahead: match if NOT followed by
  • (?<=...) — positive lookbehind: match if preceded by
  • (?<!...) — negative lookbehind: match if NOT preceded by

Example — match a number followed by "px": \d+(?=px)

Named Capture Groups

(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})

Named groups (e.g., match.groups.year) make regex results much easier to work with in code.

Try These Free Tools