Regular expression tester
Flags
Use $1, $2 for capture groups and $& for the whole match.
| # | Position | Match | Groups |
|---|
This tester runs your browser's own JavaScript engine, so the dialect is ECMAScript. Patterns written for PCRE, Python or .NET can behave differently, especially around lookbehind, atomic groups, possessive quantifiers and unicode property escapes.
What this regex tester does
A regular expression is easy to write and hard to be sure about. This page shows you what your pattern actually matched in your own text, which groups it captured and what the replacement would produce, before that pattern goes anywhere near production data.
How to use it
- 1 Type the pattern between the slashes and tick the flags you need.
- 2 Paste real text underneath, the messier the better, and press Run.
- 3 Read the highlighted view for a quick check, the table for the captured groups, and add a replacement to preview the rewrite.
Why the pattern runs in a separate worker
Some patterns explode. A nested quantifier such as (a+)+$ can force the engine to try an astronomical number of paths on a string that almost matches, and a regular expression already running cannot be interrupted from the page it started on. Running it in a worker means it can be terminated after two seconds, so a bad pattern costs you a message instead of a frozen tab.
Short reference
| \d | a digit |
| \w | a letter, digit or underscore |
| \s | any whitespace |
| . | any character except a newline |
| ^ $ | start and end of the text |
| * + ? | zero or more, one or more, zero or one |
| {2,5} | between two and five times |
| (...) | a capture group, read back as $1 |
| (?<ad>…) | a named group, easier to read in long patterns |
| [a-z] | any one character from the set |
| a|b | either the left side or the right side |
| \b | a word boundary, matches no character itself |
The dialect matters
A pattern that works here may fail in your server code and the other way round. JavaScript, PCRE, Python and .NET differ in what they support and sometimes in what the same syntax means. Test in the dialect you will deploy in, and treat this page as the right place for anything that will run in a browser.
Groups are where most mistakes hide
The match itself is often right while the captures are wrong: a group is optional and comes back undefined, or two groups swap because a bracket moved. The table shows every group of every match side by side, which is the fastest way to see that $2 is not what you assumed it was.
Nothing you type is sent anywhere
Test text is rarely made up. People paste log lines, customer records and payment references to see whether the pattern catches them. Both the pattern and the text stay in the page, so testing against real data does not mean handing that data to anyone.