About the Regex Tester
A regular expression (regex) describes a text pattern – for example "four digits, a dash, then two digits" – and is used to search, validate and rewrite text in code, editors, command-line tools and spreadsheets. Getting a pattern to match exactly what you mean is much easier when you can see the matches immediately.
This tester uses your browser’s own JavaScript regex engine, so the results are the same as RegExp, match and replace produce in JavaScript and Node.js. Matches are highlighted as you type, every match is listed with its position and capture groups, and Replace mode shows what a replacement string produces.
Patterns run in a background worker with a time limit, so a pattern with catastrophic backtracking cannot freeze the page. Your pattern and text stay in your browser.
How to use it
- Type a pattern into Regular expression, without the surrounding slashes – or click one of the Examples.
- Switch Flags on or off: g, i, m, s, u and y, plus d and v if your browser supports them.
- Paste the text to search into Test text. Matches are marked under Highlighted matches and listed under Match details with their index, length and groups.
- Choose Replace under Mode and enter a Replacement such as $<day>/$<month>/$<year> to see the Result after replacement, then click Copy result.
- Look up syntax in the Cheat sheet below the tester, and use Clear to start again.
Features
- Live highlighting and match details: Every match is highlighted in the text and listed with its index, length and numbered and named capture groups. Empty (zero-length) matches are shown as thin markers, and with the d flag the start and end of each group are included.
- Replace preview: Test a replacement with JavaScript’s syntax: $1 and $<name> for groups, $& for the whole match, $` and $' for the text before and after it, and $$ for a dollar sign.
- The real JavaScript engine: Matching uses the browser’s RegExp implementation, so behaviour and syntax errors are exactly what your JavaScript code will see.
- Protection against runaway patterns: Each run happens in a Web Worker and is stopped after 1.5 seconds. Instead of a frozen tab you get an explanation of catastrophic backtracking.
- Examples and cheat sheet: Load simple patterns for e-mail-like text, ISO dates, hex colors and repeated words, and look up common tokens and replacement codes at a glance.
Examples
Reformatting dates
Load the ISO date example and switch to Replace: the pattern captures year, month and day as named groups, and the replacement $<day>/$<month>/$<year> turns 2024-03-15 into 15/03/2024.
Finding duplicated words
The pattern \b(\w+)\s+\1\b with the i flag finds "is is" and "the the" – even when the repeated word continues on the next line. Replacing with $1 removes the duplicate.
Extracting colors from CSS
With #(?:[0-9a-f]{6}|[0-9a-f]{3})\b and the flags g and i, the match list shows every three- and six-digit hex color in a stylesheet, while invalid values such as #12345G are skipped.
Diagnosing a slow pattern
The Slow pattern example ^(a+)+$ on a long row of "a" followed by "b" is stopped after 1.5 seconds with a warning. The nested + is the problem; ^a+$ matches the same text instantly.
Limitations and notes
- Only JavaScript regex syntax is supported. Features of other flavours, such as possessive quantifiers, atomic groups, recursion, or \A and \Z, are not available, and the exact syntax supported depends on your browser.
- The test text is limited to 200,000 characters. Up to 5,000 matches are listed and highlighted; the match count and Replace mode still cover all matches.
- Each run is stopped after 1.5 seconds. A legitimate but very heavy pattern on long text can therefore be stopped as well.
- As in JavaScript, without the g flag only the first match is found and replaced.
- The example patterns are deliberately simple, for learning and quick searches. They are not complete validators – for example, the date example accepts 2024-02-30.
- Index and length are counted in UTF-16 code units, as in JavaScript, so an emoji counts as two characters.
Frequently asked questions
Which regex flavour does this tester use?
JavaScript (ECMAScript), executed by your browser’s engine. Patterns that work here work the same way in JavaScript and Node.js code. Python, PCRE (PHP) and Java patterns are often similar but differ in details such as lookbehind support, inline flags and named group syntax.
Why does my pattern only find one match?
Turn on the g (global) flag. Without it, JavaScript stops after the first match – both when matching and when replacing.
What is catastrophic backtracking?
Patterns with nested or overlapping quantifiers, such as (a+)+ or (\w|\d)*, can try an exponential number of ways to match text that almost matches. The engine may then run for minutes. Making the pattern more specific – for example ^a+$ instead of ^(a+)+$ – usually fixes it.
How do I use a captured group in the replacement?
Write $1, $2 and so on for numbered groups, or $<name> for a group written as (?<name>…). $& inserts the whole match, and $$ inserts a literal dollar sign.
Do I need to escape forward slashes?
Not in this tester: the slashes around the box are only decoration, and the pattern is passed to new RegExp() directly. Inside a JavaScript regex literal such as /a\/b/ a slash must be escaped.
Is my text sent to a server?
No. Matching runs in a Web Worker inside this page, and neither the pattern nor the text is sent over the network.