1. Home
  2. Guides
  3. Developer

How to Test a Regular Expression Step by Step

5 min readUpdated October 6, 2026

Regex TesterLive regex matching, groups and replace. Free, no sign-up.

Regular expressions are easiest to write against real sample text, one small piece at a time.

Test a pattern

  1. Open the Regex Tester.
  2. Enter the pattern and flags (g, i, m, s, u, y).
  3. Paste test text. Matches are highlighted as you type, with capture and named groups listed.
  4. Try a replacement using $1 or $<name> to preview the result.

The tester uses your browser’s JavaScript regex engine, so behaviour matches what your web or Node.js code will do.

Build it up gradually

Start with the most specific part, check it matches, then add the rest. For an ISO date:

  1. \d{4} matches the year.
  2. \d{4}-\d{2} adds the month.
  3. (\d{4})-(\d{2})-(\d{2}) captures all three parts as groups 1–3.

Flags in one line each

Patterns worth keeping

Task Pattern
Trailing spaces [ \t]+$ with the m flag
Repeated words \b(\w+)\s+\1\b
Extract key=value pairs (\w+)=([^&\s]+)
Simple email shape (not full validation) ^[^\s@]+@[^\s@]+\.[^\s@]+$

Without code

For one-off edits in plain text, Find and Replace supports regex too, and Diff Checker shows exactly what changed afterwards.