How to Test a Regular Expression Step by Step
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
- Open the Regex Tester.
- Enter the pattern and flags (
g,i,m,s,u,y). - Paste test text. Matches are highlighted as you type, with capture and named groups listed.
- Try a replacement using
$1or$<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:
\d{4}matches the year.\d{4}-\d{2}adds the month.(\d{4})-(\d{2})-(\d{2})captures all three parts as groups 1–3.
Flags in one line each
gfind all matches, not just the first.iignore upper and lower case.mmake^and$match at every line.slet.match line breaks too.utreat the pattern as Unicode (needed for emoji and\p{…}).
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.