Regex Tester & Explainer
Free regex tester for JavaScript: live match highlighting, capture and named groups, replace and split previews, a plain-English explanation and safe timeouts.
How to use Regex Tester
- 1Type a pattern, switch on the flags you need (g, i, m, s, u, y, d) and paste the text to search, or pick one of the ten common patterns.
- 2Read the highlighted text and match table in Test mode. Use Replace to preview a substitution, Split to cut the text apart, or Explain for a part-by-part description.
- 3Copy the match list, the replaced text or the split result, or load the replaced text back as the next input.
What makes it better
- Four modes on one page: Test, Replace, Split and Explain
- Matches highlighted in the text, with positions, numbered groups and named groups in a table
- Replace preview understands $1, $<name>, $& and $$; split preview shows captured pieces
- Runs in a worker with a 2 second limit, a 5,000 match cap and a 1 MB text limit, so nothing freezes
- Friendly messages for invalid patterns, plus a cheat sheet and ten common patterns, each with an honest caveat
About Regex Tester
This tester runs your pattern with your browser's own JavaScript RegExp engine against text you paste. It highlights each match, lists the start and end positions and every numbered and named group, and previews a replacement with $1, $<name> and $& or a split. The matching runs in a background worker with a two-second limit, so a pattern that backtracks badly is stopped instead of freezing the tab.
Common uses
- Check that a validation pattern accepts the inputs it should and rejects the ones it should not before it goes into code.
- Work out the right capture groups for pulling an order number or date out of a log line.
- Preview a search-and-replace across a pasted block of text before running it in an editor or script.
- Understand a pattern found in someone else's code by reading its token-by-token explanation.
Example
Input
Write to [email protected] or [email protected] today.
Result
/(?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+)/g 2 matches 1. "[email protected]" at 9-24 groups: 1="ada", 2="example.com", user="ada", domain="example.com" 2. "[email protected]" at 28-55 groups: 1="sales+uk", 2="mail.example.co.uk", user="sales+uk", domain="mail.example.co.uk"
Good to know
- Only JavaScript (ECMAScript) syntax is tested. PCRE, Python, Java, .NET and Go differ in places, and the page lists the main differences under the tester.
- The Explain mode reads the common syntax only. It does not cover everything, such as the v flag's set notation, and it never runs the pattern.
- The matcher stops after 2 seconds, 5,000 matches or 1 MB of text. A stopped pattern is reported, but the page cannot say which part is slow.
Regex Tester FAQ
Which regex flavour does this tester use?
JavaScript. The pattern is handed to the RegExp engine of the browser you are using, so results match what the same pattern does in a web page or Node.js. Features that only exist in other engines, such as possessive quantifiers, atomic groups, inline flags like (?i) and \A or \Z anchors, will be reported as errors or behave differently.
Why was my regex stopped after two seconds?
Some patterns take exponentially longer as the text grows, a problem called catastrophic backtracking. Nested quantifiers such as (a+)+$ or overlapping alternatives such as (a|aa)+ are typical causes. The tester runs the match in a background worker and ends it after two seconds, so the page keeps working. Make the pattern more specific, remove the nesting or shorten the text.
What do the g, i, m, s, u, y and d flags do?
g finds every match instead of the first, i ignores letter case, m lets ^ and $ match at each line, s lets the dot match line breaks, u switches on full Unicode behaviour and \p{…} classes, y matches only at the exact search position, and d records the start and end of each group, which the match table shows as ranges.
How do I use captured groups in the replacement?
In Replace mode write $1, $2 and so on for numbered groups, $<name> for a named group, $& for the whole match and $$ for a literal dollar sign. For example, swapping (\w+) (\w+) with $2 $1 reverses two words. Without the g flag only the first match is replaced.
Does the pattern or text I type leave my computer?
No. Matching runs in your browser, inside a Web Worker on the same page, and the pattern and text are not uploaded or stored. Closing or reloading the tab discards them.