Regex Tester
Type a regular expression and some test text to see every match highlighted, with its position and capture groups. The tester uses your browser's JavaScript regex engine.
Write the pattern without the surrounding slashes. Pasting /pattern/flags also works; the flags are picked up automatically.
Replacement result
Matches and groups
Your pattern and test text are processed inside your browser and are never sent to our server.
How to use the Regex Tester
- Type your pattern in the top box without the surrounding slashes, for example
\d+. Pasting a literal such as/\d+/gialso works. - Tick the flags you need. Leave g on to find every match; without it, only the first match is shown, just like
RegExp.exec(). - Paste the text to search. Matches are highlighted in alternating colors and listed in a table with their position and each capture group.
- To test a substitution, fill in Replace with. Use
$1,$2for numbered groups,$<name>for named groups and$&for the whole match.
Which regex flavor this uses
This tester runs your pattern through your own browser's JavaScript engine (new RegExp(pattern, flags)), so the results match what the same pattern will do in JavaScript or TypeScript code running in that browser or in Node.js. Other languages use different flavors: PCRE (PHP), Python's re, Java and .NET support features JavaScript lacks, such as possessive quantifiers or atomic groups, and treat some syntax differently. A pattern that works here is not guaranteed to work in those languages, and vice versa.
What the flags do:
- g (global) finds all matches instead of stopping at the first.
- i ignores case. m (multiline) makes
^and$match at the start and end of each line. s (dotAll) lets.match line breaks too. - u turns on Unicode mode, needed for
\p{L}-style property escapes and to treat emoji as single characters. v is the newer Unicode sets mode with extra set syntax; it appears only if your browser supports it, and it cannot be combined with u. - y (sticky) only matches at the exact position where the previous match ended, so matching stops at the first gap.
Safety features
Patterns that can match an empty string, such as a* or \b, would loop forever in a naive tester. This one advances one character (one code point in Unicode mode) after each empty match, the same way String.prototype.matchAll does, and shows empty matches as thin bars. Some patterns, for example (a+)+$, can take exponential time on text that nearly matches. Matching runs in a separate background thread and is stopped after 1.5 seconds, so the page stays usable and you get a message instead of a frozen tab. The match list stops at 5,000 matches.
Frequently asked questions
Why does my pattern work here but not in Python or PHP?
Each language has its own regex flavor. This tool uses JavaScript's. Common differences include lookbehind support in older engines, named-group syntax ((?P<name>…) in Python versus (?<name>…) in JavaScript) and features like possessive quantifiers that JavaScript does not have.
Do I need to escape forward slashes?
Not here. Slashes only need escaping inside a JavaScript regex literal such as /a\/b/. In this box you enter the pattern as a string, so a/b is fine.
Why does only one match appear?
The g flag is probably off. Without it, JavaScript returns only the first match. Turn on g to see all of them. With y (sticky) on, matching also stops at the first position that does not match.
What does "took longer than 1.5 seconds" mean?
Your pattern triggered heavy backtracking, where the engine tries an enormous number of ways to match. It is a sign the pattern could also hang a real application. Nested quantifiers such as (\w+)* are the usual cause; make the inner part more specific or anchor the pattern.
Is my test text sent anywhere?
No. The pattern and text are processed in a background thread of this browser tab. Nothing leaves your device.
Sources: MDN Web Docs: Regular expression modifiers and flags