Regex Tester — JavaScript Match and Replace
JavaScript regex tester with flags, match highlighting, group table and replace preview
Runs in your browser · nothing is uploaded
What it is
Regular expressions are easy to get subtly wrong. Enter a pattern and some text and this tool shows at once where it matches, marks each match in color, and lists every match with its position and capture groups. Add a replacement string to preview the substituted text.
How to use
- Type the pattern without surrounding slashes (a pasted
/pattern/gifrom code is split into the pattern and its flags), for example(\d+)-(?<word>[a-z]+). - Tick the flags you need.
g, which finds every match, is on by default. - Paste the test text. Matches are highlighted and the table lists each match’s position and groups.
- In the replacement field use
$1,$<name>or$&to see the result, then copy it. To delete every match, turn on Show the replacement and leave the field empty.
How it works
- Flags:
gglobal,iignore case,mmakes^and$work per line,slets.match newlines,uenables Unicode mode,ymatches only at the current position (sticky). - Without
gonly the first match is returned. With bothgandy, only matches that follow each other without a gap are found. - Empty matches (
a*,^, the empty pattern) advance the position by one character and the search continues; withuthe step is a whole code point. - Replacement syntax is that of
String.prototype.replace:$$,$&,$`,$',$1to$99and$<name>. - Safeguards: at most 1,000 matches, 200,000 characters of text and 5,000 of pattern, plus a 1.5 second run limit. The limit works by running the match in a Web Worker and terminating it, which is why the main page never freezes.
Examples
| Pattern | Flags | Text | Result |
|---|---|---|---|
\d+ |
g | a1 b22 c333 |
1, 22, 333 |
[가-힣]+ |
g | abc 한글 test 테스트 |
한글, 테스트 |
a* |
g | baac |
four matches, at positions 0, 1 (aa), 3 and 4 |
(?<y>\d{4})-(\d{2}) |
2024-05 |
group 1 y = 2024, group 2 = 05 |
Notes
[가-힣]catches precomposed Korean syllables, and emoji can be matched with theuflag plus\p{Emoji_Presentation}.- Your pattern and text are never sent to a server.
FAQ
Which regex flavor is this?
It uses your browser's own JavaScript (ECMAScript) regex engine, so syntax differs from Python, PCRE or Java in places. Possessive quantifiers and inline flags such as (?i) are not available, and named groups are written (?<name>...).
What happens if a pattern runs for too long?
Matching runs in a separate Web Worker that is terminated after 1.5 seconds. Nested repetition such as (a+)+$ can slow down exponentially on slightly longer input (catastrophic backtracking). When that happens you see a message and the page stays responsive.
Are there limits on matches or text length?
The first 1,000 matches are shown, the text can be up to 200,000 characters and the pattern up to 5,000. Beyond that the list is truncated or a message is shown instead.
Can a pattern that matches the empty string loop forever?
No. After an empty match the search position (lastIndex) is moved one character ahead, so the loop always ends. With the u flag it steps over a whole code point, so an emoji is never split.
Related tools
URL Parser
URL component breakdown with decoding, IDN hosts and query parameter editing
Cron Expression Parser
Cron expression explainer with 5/6 fields, next 5 runs and time zones
JSON Formatter
Beautify, minify and validate JSON, sort keys, errors with line and column
URL Encoder/Decoder
A URL percent-encoder and decoder that handles Unicode and emoji