How to Test a Regex
Online Free
Live matching, capture-group inspection, and replacement preview — same JS regex engine your code will run, only with a UI.
Open Regex TesterWhy test regex in a dedicated tool?
You can absolutely write regex in your editor, run the code, and read the output. But that's a slow loop — write, save, run, scroll, edit, repeat. A regex tester collapses that into one feedback cycle: type the pattern, see matches highlighted instantly. For non-trivial patterns this is the difference between five minutes and an hour.
Live testing also surfaces the kind of bugs that production code hides — accidental greedy quantifiers, wrong flag combinations, edge cases your test data doesn't cover. Once a pattern works against representative input here, you can paste it straight into your codebase with confidence.
Step-by-step: build and verify a regex
Open the Regex Tester
Visit the free Regex Tester. The tool uses the JavaScript regex engine — same flavor used in Node.js, V8, and any client-side JS runtime.
Type your pattern
Enter the regex without delimiters — e.g. `\b[A-Z][a-z]+\b` for capitalised words. The engine parses it as you type and reports compile errors immediately.
Set the flags you need
Toggle g (global), i (case-insensitive), m (multiline), s (dotall), and u (Unicode). Active flags appear in the URL so you can share a link to a specific test setup.
Paste sample text into the input
Drop in a representative chunk of the text you want to match against. Matches are highlighted live; non-matching regions stay plain.
Inspect capture groups
When your pattern has parentheses, the right-hand panel shows each captured group per match — useful for debugging \1, \2 backreferences and replacement strings.
Try replacements
Switch to the Replace tab, type your replacement string with $1, $2 backreferences, and see the rewritten output update on every keystroke.
Pro tips for cleaner patterns
Anchor with \b for whole-word matches
Without word-boundary anchors, /cat/ matches inside 'category', 'concatenate', etc. Use /\bcat\b/ to require a word boundary on each side. The tester shows you the exact match span so this is easy to verify.
Use named capture groups for readability
/(?<year>\d{4})-(?<month>\d{2})/ is clearer than /(\d{4})-(\d{2})/. The tester reports captures by name, which becomes invaluable when patterns grow past 3 groups.
Start non-greedy, then tighten
Greedy quantifiers (.*) often eat too much. Try .*? first; if that under-matches, refine to a character class like [^,]* or [^<]+ for HTML. Watching the highlight shift as you tweak is the fastest way to learn.
Save complex patterns as URLs
The tester encodes your pattern, flags, and sample text into the URL. Bookmark it or paste into a code review to share an exact match scenario with a colleague.
Patterns and sample data stay private
Production logs, user PII, internal API responses — paste anything as sample text. The regex executes in your browser's own JS engine. No upload, no logging, no "optional" analytics on content.
Frequently asked questions
Which regex flavor does this use?
JavaScript / ECMAScript regex — the flavor in V8 (Chrome, Node), SpiderMonkey (Firefox), and JavaScriptCore (Safari). It's similar to PCRE but with notable differences: no possessive quantifiers, no recursion, no \K, and Unicode requires the u flag explicitly.
Can I test PCRE or Python regex here?
Not natively — the engine is JS. For most patterns the differences don't matter, but if you need PCRE-specific features (recursion, \K, possessive quantifiers) or Python-specific syntax (verbose mode, named groups in a different format), use a language-specific tool.
Why is my pattern matching too much?
Almost always greedy quantifiers. /.*/ eats every character it can. Switch to /.*?/ (lazy) to match as little as possible. The visual highlighting in the tester shows you exactly which characters are being consumed — making greedy bugs immediate to spot.
What's the difference between match and exec?
With the g flag, .match() returns all matches as a flat array. .exec() returns one match at a time and tracks state on the regex object — useful when you need capture groups for each match. The tester shows the equivalent of .matchAll() output: every match with its capture groups.
Is my text or pattern sent anywhere?
No. The regex engine is the browser's own — same one you'd use in DevTools. Your pattern, sample text, and replacement strings stay on your device. We log nothing about regex content.
Can I match across multiple lines?
Yes — toggle the m flag. Without m, ^ and $ only match the start and end of the entire input. With m, they match line boundaries inside the input. Combine with the s flag if you want . to also span newlines.