Skip to content
Flavor
ECMAScript
Deadline
500 ms
Runtime
Browser

Replace regular-expression matches with explicit substitution text

Transform text with JavaScript replacement-string semantics while keeping the global-versus-first choice visible.

Local processingNo sign-upKillable worker

Input

Use JavaScript replacement tokens intentionally; add g only when every match should change.

Local

The g flag selects replace-all behavior for String.prototype.replace.

Replaced text

Submit the example or replace it with your own values. User matching runs only in a disposable browser worker.

What this tool proves

Explicit ECMAScript behavior

Replacement strings are not literal by default: JavaScript recognizes substitutions such as $&, $1, and $<name>. The route keeps replacement text in its own field so that pattern syntax and replacement syntax are not conflated.

Replacement syntax and match scope remain explicit

Replacement strings are not literal by default: JavaScript recognizes substitutions such as $&, $1, and $<name>. The route keeps replacement text in its own field so that pattern syntax and replacement syntax are not conflated.

Without g, only the first match is replaced; with g, every match within the worker budget is eligible. Replacement input is capped at 64 KiB and the final output at 1 MiB before it is returned to the page.

Bounded execution protects the page without hiding risk

Any operation that runs a user pattern is isolated in a disposable Web Worker. Tool Swim terminates that worker after 500 ms, caps patterns at 4 KiB and text at 256 KiB, and never runs user matching on the interface thread.

Pattern, flags, text, replacement, matches, and explanations stay in the current browser tab. The public tool makes no developer API request, stores no preset, and works without an account or telemetry.

Primary references

Questions and answers

Related Regex tools