How do you use this tool?
- Type or paste your regular expression into the Pattern field (without surrounding slashes).
- Select any flags you need: g (global), i (case-insensitive), m (multiline), s (dotAll).
- Paste your test string into the input area below.
- Matches highlight instantly — hover over a match to see its index and capture groups.
- Adjust the pattern and watch the results update with every keystroke.
What This Tool Does
The Regex Tester provides a live sandbox for JavaScript regular expressions. Paste a pattern and a test string, and the tool highlights every match in real time — no page reload, no button press. Capture groups are extracted and labeled so you can inspect each part of a complex pattern independently.
How It Works
The tool feeds your pattern and flags directly into JavaScript’s RegExp constructor and runs String.prototype.matchAll() (or exec() in a loop for stateful iteration). Each match object contains:
- Full match — the entire substring that matched
- Index — the zero-based position in the source string
- Capture groups — numbered (
$1,$2) and named (groups.name) sub-matches
Everything runs in your browser. Your pattern and test data never leave your machine.
What Regex Flags Are Available?
| Flag | Name | Effect |
|---|---|---|
g | Global | Return all matches, not just the first |
i | Case-insensitive | A matches a |
m | Multiline | ^ / $ match line boundaries |
s | DotAll | . matches \n and \r |
u | Unicode | Enable full Unicode matching |
d | Indices | Include start/end indices per group (ES2022) |
What Are Common Use Cases?
Validating US phone number formats — US phone numbers appear in dozens of formats: (555) 867-5309, 555-867-5309, 5558675309. A regex like \(?\d{3}\)?[\s\-]?\d{3}[\s\-]?\d{4} matches all variants. Test every format before deploying to a form validator.
Parsing log files — Server logs from Apache, Nginx, AWS CloudFront, and Cloudflare Workers follow structured but messy formats. Build a pattern against a sample line, verify capture groups extract IP, timestamp, status code, and path correctly, then port it to your log-parsing script.
Extracting data from HTML or CSV — Quick scraping jobs often start with a regex. Test your pattern against a sample before running it across thousands of rows.
Form validation — ZIP code (\d{5}(-\d{4})?), SSN (\d{3}-\d{2}-\d{4}), email, and credit card patterns all benefit from live testing before going into production code.
Find-and-replace in editors — VS Code, JetBrains IDEs, and Sublime Text all support regex find-and-replace. Prototype the pattern here where you can see matches highlighted, then paste it into your editor.
Frequently Asked Questions
What is the difference between test() and match()?
RegExp.prototype.test(str) returns a boolean — useful when you only need to know if a pattern matches. String.prototype.match() returns the match array. This tool uses matchAll() to surface all matches and their groups.
Why does my regex work in one tool but not another?
Regex syntax is not fully standardized across languages and tools. JavaScript supports named capture groups ((?<year>\d{4})), lookbehind assertions ((?<=@)\w+), and Unicode property escapes (\p{L}) — features absent or syntactically different in older tools. Always validate in the environment where the code will run.
Last updated: