How to use the regex tester
- Type your regular expression into Pattern, for example
(?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+). - Enter any Flags, such as
gi. - Paste realistic Test text, including lines that should not match.
- Optionally fill in Replace with to preview a replacement.
- Read the match count, the match table with every group, the highlighted text, the result after replace and the token-by-token explanation.
What it does and when to use it
Regular expressions are powerful and easy to get subtly wrong. Testing a pattern against real text before it goes into code saves a lot of debugging. This tester shows you not just whether a pattern matches but exactly what each group captured and why.
Use it to:
- Build a validation pattern for a form field, such as a postcode or an order number.
- Write the search and replace for a bulk edit in your editor or codebase.
- Pull values out of log lines, such as dates, IDs or IP addresses.
- Understand a pattern someone else wrote, with the explanation table.
- Spot a pattern that could hang on bad input before it reaches production.
If you need a quick reminder of the syntax, the Regex Cheat Sheet lists the common tokens. To see what a replacement changed across a whole file, compare before and after in the Diff Checker. For checking token payloads you have extracted, use the JWT Debugger.
How it works
The tool compiles your pattern with JavaScript’s RegExp and runs it against your text in the browser. It lists each match with its position (index) and every numbered and named group. The highlight view marks matches in the original text. If you enter a replacement, it runs text.replace with your pattern, so $1 and $<name> work exactly as in JavaScript.
The explanation splits the pattern into tokens, such as groups, character classes, quantifiers and anchors, and describes each one in plain English. Invalid patterns and unknown flags are reported with a clear message instead of failing silently.
Worked examples
An optional letter. colou?r with the g flag on “color colour” gives Matches: 2. The explanation describes ? as “repeated optionally (zero or one time)”.
Reformatting dates with named groups. The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) finds two dates in “Due 2026-10-03, paid 2026-10-15.” and captures year, month and day for each. With the replacement $<day>/$<month>/$<year>, the text becomes Due 03/10/2026, paid 15/10/2026.
A risky pattern. (a+)+$ on “aaaa” matches, but the tool warns about catastrophic backtracking, because a quantifier sits inside another one.
A typo in the flags. Flags gq give Unknown flag q, along with the list of valid JavaScript flags.
Limits and tips
- Regular expressions cannot reliably parse nested formats such as HTML or JSON. Use a proper parser for those.
- The pattern runs on your device, so a pathological pattern on very long text can make the page slow.
- Lookbehind and the v flag need a recent browser. Check support if your code must run on older browsers.
Frequently asked questions
Which regex flavour does this use?
What do the flags mean?
How do I use a capture group in the replacement?
What is catastrophic backtracking?
Can I paste a pattern with slashes, like /abc/gi?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.