Batch Regex Replace Simulator
Preview ordered regex replacements across multiple virtual files — privately in your browser
Virtual files
Replacement rules
Rules run top to bottom. Use $1 or $<name> for capture groups; add g to replace every match.
Examples
Rearrange with named groups
files: [{ name: "names.txt", content: "John Doe" }]
rules: [{ pattern: "(?<first>\\w+) (?<last>\\w+)", replacement: "$<last>, $<first>" }]output: "Doe, John", matches: 1Named captures expand through $<name> with native replace semantics; the diff records line 1 before/after.
Chained rules with case-insensitive match
files: [{ name: "pets.txt", content: "I have a CAT." }]
rules: [{ pattern: "cat", flags: "i", replacement: "dog" }, { pattern: "dog", replacement: "fish" }]output: "I have a fish.", totalMatches: 2, changedFiles: 1Rule 1 matches CAT via the i flag, then rule 2 rewrites its dog output to fish — ordering is the feature.
About this tool
Batch Regex Replace Simulator dry-runs ordered find-and-replace rules over virtual files with simulateBatchRegexReplace(files, rules), taking { name, content } inputs and { pattern, flags?, replacement } rules without mutating the caller's data. Each rule compiles via new RegExp(pattern, flags ?? ""); an empty pattern becomes a no-op matcher, while an invalid pattern aborts the whole run with { files: [], totalMatches: 0, changedFiles: 0, error: "Rule N: invalid regular expression — <message>" } naming the offending 1-based rule index. Replacement uses native String.replace semantics, so $1 numbered groups, $<name> named groups, $&, and $$ all work — and unknown $<missing> names are left as literal text exactly as JavaScript does.
Rules apply in array order with full chaining: each rule transforms the output of the previous one (foo → fooBar → foobaz across two rules), and match counting mirrors replace behavior — global-flagged rules count every matchAll hit on a cloned regex, while non-global rules count at most one via a single test. Per-file results report { name, original, output, matches, diffs }, where diffs are per-line { line, before, after } entries, and the run aggregates totalMatches plus changedFiles (files whose output differs from the original).
Edge behavior is explicit rather than magical: no flags means first-match-only replacement ("red red red" → "blue red red" with one counted match), empty rule lists return inputs unchanged with zero matches and empty diffs, and the error path returns no file results at all so callers must check error before reading files.
How to use this tool
Add files and rules
Supply virtual files with names and contents, then stack rules in execution order with pattern, optional flags (g, i, m, s, u, y), and a replacement using $1 or $<name> references.
Check the error slot first
If error names a rule index with the underlying RegExp message, fix that pattern — no file outputs are returned on the error path.
Review diffs before applying
Read each file's output, match count, and per-line before/after diffs plus the run totals, then apply the same ordered rules to the real files.
Control match breadth with flags
Add g to replace every occurrence, i for case-insensitive matching, and named groups (?<name>…) with $<name> for readable rearrangements.
Use cases
Previewing mass renames
Dry-run identifier or label rewrites across many virtual files and inspect per-line diffs before touching the repo.
Sequencing codemod passes
Chain normalization then transformation rules (e.g. case-fold then rename) with exact counts per pass.
Validating regex rules
Catch invalid patterns up front via the Rule N error message instead of discovering them mid-migration.
Common mistakes
Mistake:Expecting an invalid pattern to throw.
Fix:The simulator returns { error } with empty files instead of throwing. Branch on result.error before reading result.files.
Mistake:Forgetting g and expecting all matches replaced.
Fix:Without the global flag only the first match is replaced and counted. Add flags: "g" (or "gi") for whole-file rewrites.
Mistake:Assuming unknown $<names> expand to empty.
Fix:JavaScript leaves unknown named references literal ("$<missing>" stays in the output). Verify group names against the pattern when output contains dollar syntax.
Frequently asked questions
What does this tool do?
It dry-runs ordered regex replacement rules over virtual files with simulateBatchRegexReplace, reporting per-file output, match counts, per-line before/after diffs, and run totals — without modifying the inputs.
Why didn't my invalid pattern throw, and why only one replacement?
Invalid patterns return { error: "Rule N: invalid regular expression — …" } with empty files instead of throwing — always check error first. Single replacements mean the global flag is missing: without g only the first match is replaced and counted.
Is my file content uploaded or stored?
No. Rule compilation, matching, and diffing run entirely in your browser — file contents and patterns never leave your device.
How do named groups and rule ordering work?
Capture with (?<name>…) and expand with $<name> under native replace semantics — e.g. (?<first>\w+) (?<last>\w+) to "$<last>, $<first>" turns John Doe into Doe, John (unknown names stay literal). Rules chain in array order, so a cat → dog rule followed by dog → fish yields fish, and the i flag makes matching case-insensitive.
Related guides
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
AI Function Calling Schema Generator
Generate function calling JSON schemas from TypeScript interfaces
Algorithm Arena & Data Structure Visualizer
Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.
Ansible Playbook Generator
Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML