Regex Tester
Test a JavaScript regular expression against sample text, with every match highlighted inline and capture groups listed.
This guide is not yet available in your language and is shown in English.
Tool guide
What this tool does
Regex Tester runs a JavaScript regular expression against sample text in real time, highlighting every match inline, listing each match’s index and capture groups in a table, and optionally previewing a find-and-replace result.
Writing a regular expression that looks right is one thing; confirming it actually matches what you intend, and only what you intend, against real sample text is another. A small mistake, a greedy quantifier matching too much, a missing escape, an off-by-one in a character class, is easy to miss just by reading the pattern.
This tester runs your pattern against JavaScript’s native RegExp engine as you type, highlighting every match directly in your sample text, listing each match’s position and any captured groups in a table below, and optionally showing what a find-and-replace with that pattern would actually produce.
How to use Regex Tester
- Enter your regular expression Pattern.
- Set any Flags you need (g for global, i for case-insensitive, m for multiline, etc.).
- Paste or type your sample Test string.
- Review the highlighted matches and the Match details table.
- Toggle Preview find & replace to test a replacement pattern.
Tips for better results
- Add the g flag to see all matches rather than just the first one; without it, only the first match is found, which is a very common source of confusion.
- In the replacement field, $1, $2 etc. refer to capture groups, and $& refers to the entire matched text, exactly as in JavaScript’s String.replace().
- An empty match (possible with patterns like a* against a string with no "a") is shown with a note so you can distinguish it from no match at all.
- This uses JavaScript’s own RegExp engine, so whatever works here will behave identically in your actual JavaScript or TypeScript code.
Common use cases
- Debugging why a regular expression in your code isn’t matching what you expect.
- Building and refining a validation pattern (phone numbers, usernames, codes) against real sample inputs.
- Testing a find-and-replace pattern before running it across a large file or codebase.
- Learning regex behaviour interactively by tweaking a pattern and watching the highlighted matches update live.
Common mistakes to avoid
- Forgetting the g (global) flag and being confused why only one match highlights when you expected several.
- Not escaping special regex characters (like . or ( ) when you mean them literally, causing the pattern to match far more than intended.
- Assuming behaviour here will differ from your own code; since this uses the same JavaScript RegExp engine your code runs on, a working pattern here is confirmed working there too.
Frequently asked questions
Which regex flavour does this use?
JavaScript’s native RegExp engine, the exact same engine that runs in your browser and in Node.js, so results here match your real code exactly.
Why does my pattern only match once?
Add the g (global) flag; without it, JavaScript’s regex methods stop after the first match by default.
How do I reference capture groups in a replacement?
Use $1, $2 and so on for numbered groups, $<name> for named groups, and $& for the entire match, the same syntax as JavaScript’s String.replace().
Is my test data sent anywhere?
No, matching happens entirely in your browser using JavaScript’s built-in regex engine; nothing you type is ever transmitted anywhere.
Related articles
Feedback & suggestions
Help us improve Regex Tester. We read every message.