Regex Tester
Test a JavaScript regular expression as you type. See every match highlighted, the capture groups, a replace preview and a plain-English breakdown of the pattern. Runs in your browser.
Replace (optional)
Try an example:
Private by design: your pattern and text stay on your device. Matching runs in a separate, time-limited worker so a runaway pattern can’t freeze the page, and nothing is uploaded or stored.
How to use the Regex Tester
- Type your pattern into the top box. You can paste a full JavaScript literal such as
/\d{3}-\d{4}/giand the flags are picked up for you. - Tick the flags you need.
gfinds every match rather than just the first,iignores upper and lower case,mmakes^and$work on each line,slets.match line breaks, anduturns on full Unicode support. - Paste some test text. Matches are highlighted as you type, in alternating colours so neighbouring matches are easy to tell apart.
- Check the Matches table for each match’s position and what every capture group caught, including named groups.
- Open Replace to preview a find-and-replace. Use
$1,$2for numbered groups,$<name>for named groups and$&for the whole match. - Press Copy as JS to copy the pattern as a ready-to-paste JavaScript regular expression literal.
If you enjoy what we do, consider supporting us. Every little bit means the world! Support Catpool on Ko-fi
What the breakdown tells you
Regular expressions are compact, which makes them hard to read back a week later. Under the results, the tester splits your pattern into its pieces and explains each one in plain English: character classes like [A-Z], shorthand such as \d and \b, groups, look-aheads and how many times each part repeats. Nested groups are indented, so you can see at a glance where each group starts and ends. If a pattern isn’t doing what you expect, reading the breakdown line by line is often the quickest way to spot the mistake, such as a missing escape before a dot, or a greedy .* swallowing more than you meant.
Which regex flavour is this?
This tool uses the JavaScript (ECMAScript) engine built into your browser, so results match exactly what you’ll get in Node.js, browser code, TypeScript and most front-end frameworks. It supports modern features including named groups (?<year>\d{4}), look-behind (?<=£)\d+, Unicode property escapes \p{L} with the u flag, and the s (dot-all) flag.
Other languages are mostly similar but not identical. PCRE (PHP), Python’s re, Java and .NET share the core syntax, but differ in details: Python writes named groups as (?P<name>…), PHP patterns need delimiters, and possessive quantifiers or atomic groups such as a++ and (?>…) aren’t available in JavaScript. For everyday patterns like postcodes, dates and email checks, a pattern that works here will usually work elsewhere with little or no change.
Safe from runaway patterns
Some patterns can take an extremely long time on certain text. This is called catastrophic backtracking, and it’s the cause of real outages (sometimes called ReDoS). The classic example is a nested repeat such as (a+)+$ tested on a long line of a’s followed by another character. On many testing sites this freezes the browser tab.
Here, matching runs in a separate background worker with a time limit of 1.5 seconds. If a pattern takes longer, the tester stops it and tells you, rather than hanging the page. It also warns when it spots a repeated group that contains its own repeat. If you see that warning, make the inner part more specific, for example [^,]+ instead of .+, or remove the outer repeat.
Tips for writing better patterns
- Anchor when you can. Use
^and$(or\bfor word boundaries) so the pattern can’t match part of a longer string by accident. - Escape special characters.
. * + ? ( ) [ ] { } | ^ $ \ /all have special meanings. To match a real full stop, write\.. - Prefer specific classes to dot.
[^"]*(anything except a quote) is faster and safer than.*?for matching inside quotes. - Use non-capturing groups
(?:…)when you only need grouping, so your$1,$2numbers stay simple. - Don’t validate everything with regex. Email addresses, URLs and HTML are better checked with a proper parser. A simple pattern is fine to catch obvious typos, but the only real proof an email address works is sending it a message.
Privacy
Your pattern and test text never leave your device. There’s no server involved: matching is done by your browser’s own JavaScript engine in a temporary worker that’s thrown away after each run. Nothing is uploaded, logged or saved, so it’s safe to test against real log files, customer data or private documents.
Frequently asked questions
Why does it only find one match?
Without the g (global) flag, JavaScript stops after the first match. Tick g to find them all.
Why don’t ^ and $ match each line?
By default they mean the start and end of the whole text. Tick m (multiline) to make them work on every line.
What does an empty match mean?
Some patterns, like \d* or a look-ahead on its own, can match zero characters. These are shown as a thin red marker in the highlighted text and as “(empty)” in the table.
Can I test Python or PHP patterns?
Mostly, yes. Paste the pattern without the language’s quotes or delimiters. Features that JavaScript doesn’t support, such as possessive quantifiers, will show an error.
Is there a limit?
The table lists the first 200 matches and highlighting stops at 1,000, so very large files stay quick to scroll. Test text can be up to 200,000 characters.
Related: Catpool home, Developer, JSON Formatter, Diff Checker, URL Encode/Decode, Text Cleaner.
