Find and Replace Online — Text Replace with Regex & Backreferences
Paste any chunk of text — config file, log dump, source code, prose draft — type what you want to find, type the replacement, and the result updates live with a count of how many substitutions were made. Toggle case-insensitive matching for the obvious ("TODO" matching "todo") and toggle regex mode for capturing groups, alternation, anchors, and character classes. Replacement strings support `$1`, `$2` etc. for backreferences in regex mode, so "`(\w+) (\w+)`" with replace "`$2 $1`" swaps every word pair. Useful for cleaning up exported data, fixing a typo across a long document, refactoring patterns in code without booting an editor, normalizing whitespace, or batch-renaming entries in a list.
About this tool
All replacement runs inside a Web Worker so a catastrophic-backtracking regex (the classic `(a+)+$` against a long string) cannot freeze the page — if the worker doesn't respond in time it's terminated and you see a friendly error instead of a crashed tab. In literal mode the find string is escaped against regex special characters before being passed to a global RegExp, so `.`, `*`, `(`, `)` etc. match themselves rather than acting as metacharacters. In regex mode your pattern is used verbatim with the `g` flag (always replace all occurrences) plus `i` when case-insensitive is on, and replacement uses the standard JavaScript `String.prototype.replace` semantics — `$&` for the whole match, `$1`-`$9` for capture groups, `$$` for a literal dollar sign. Errors (unbalanced parentheses, invalid character class, lookbehind not supported in the runtime) surface inline rather than silently producing the wrong output. Use cases: redact a list of email addresses with a single regex, swap `lastname, firstname` to `firstname lastname` with backreferences, normalize line endings, rip ANSI color codes out of a copied terminal log, or reformat phone numbers from `(123) 456-7890` to `+1-123-456-7890`.
- Literal mode — find string escaped, no regex syntax surprises
- Regex mode — full JavaScript regex with capture groups + backreferences
- Case-insensitive toggle (adds `i` flag in regex mode)
- Replacement supports $1-$9 backreferences and $& for whole match
- Web Worker isolation — catastrophic backtracking can't freeze the page
- Worker timeout fires a friendly error instead of crashing the tab
- Live count of how many substitutions happened
- Inline regex error messages (unbalanced parens, invalid class, etc.)
- Reactive — runs as you edit any of the three fields
- Useful for redaction, refactoring, normalizing data, fixing repeated typos
Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).
Frequently asked questions
What is catastrophic backtracking, and how does the Web Worker help?
Catastrophic backtracking happens when a regex with nested quantifiers (the classic `(a?){29}a^29` benchmark Cox uses, or `(a+)+$` against a long string of 'a's followed by 'b') tries every possible split between the inner and outer groups before failing. As input grows, the number of split combinations grows exponentially. Russ Cox's 2007 article 'Regular Expression Matching Can Be Simple And Fast' (swtch.com) demonstrated that backtracking engines (Perl, Python, JavaScript) can take 60+ seconds on a 29-character pathological input that Thompson-NFA engines (the construction Thompson described in CACM 1968) match in 20 microseconds. JavaScript regex uses backtracking, so a malicious or accidental nested-quantifier pattern on a long string would freeze the page. Running the regex inside a Web Worker (defined in the WHATWG HTML Living Standard) means it executes in a separate thread; if the worker doesn't respond before a configured timeout, the main thread terminates it via the WHATWG terminate-a-worker algorithm and surfaces an error.
Why does literal mode escape regex special characters?
ECMA-262 specifies that a RegExp constructor string interprets `.`, `*`, `+`, `(`, `)`, `[`, `]`, `?`, `\\`, `^`, `$`, `|`, `{`, `}` as metacharacters with their respective regex meanings. Literal-mode find strings need these to match themselves: `.` should match a period, not any character; `*` should match an asterisk, not act as a quantifier. The escape pass wraps each metacharacter with a backslash before the string is passed to the RegExp constructor, so `(name)` becomes `\\(name\\)` and matches the literal text '(name)'. Without escaping, a literal-mode search for `.com` would match every three-character sequence ending in 'com', which is rarely what the user wants.
How do $1, $&, and other replacement references work?
ECMA-262's String.prototype.replace defines the replacement-string syntax: `$&` is the entire match, `$\`` (back-tick) is the portion of input before the match, `$'` (apostrophe) is the portion after, and `$1`–`$9` reference numbered capture groups in the regex pattern. In regex mode, a pattern like `(\\w+) (\\w+)` with replacement `$2 $1` swaps every adjacent pair of word tokens. ES2018 added named groups: `(?<first>\\w+) (?<last>\\w+)` with replacement `$<last> $<first>` does the same with names. A literal `$` in the replacement is written `$$`. JavaScript's replace does NOT recognize backslash-style escapes (`\\1`, `\\n`) from POSIX/Perl regex — only the dollar-sign forms.
Does this tool support modern regex features — lookbehind, named groups, Unicode property escapes?
Yes. The tool uses the JavaScript runtime's RegExp directly, so any feature the browser engine supports is available — lookbehind `(?<=...)` and `(?<!...)` from ES2018, named capture groups `(?<name>...)` and `\\k<name>` references from ES2018, Unicode property escapes `\\p{Letter}` and `\\P{Number}` from ES2018 (with the `u` flag), and the `s` (dotAll) flag from ES2018. Browsers older than ~2023 (notably Safari 16.3 and earlier for lookbehind) surface a clear SyntaxError inline rather than silently producing wrong output. ECMA-262 does NOT support atomic groups `(?>...)` or possessive quantifiers (`*+`, `++`) found in PCRE/Perl/Java; for patterns where atomic groups would be the natural defense against backtracking, the safer approach is to rewrite the pattern to avoid nested quantifiers altogether.
How does this tool handle accessibility for screen readers?
The substitution count and the result region sit inside an aria-live="polite" region, the W3C WCAG Success Criterion 4.1.3 (Status Messages, introduced in WCAG 2.1, Recommendation 5 June 2018; carried unchanged into WCAG 2.2, Recommendation 5 October 2023) pattern. Polite live regions queue announcements after any speech in progress, so editing the find or replace fields announces the new substitution count without interrupting the user mid-sentence. Screen readers (NVDA, JAWS, VoiceOver) consume the live region automatically; the user does not need to do anything else.
Sources (5)
- ECMA International (2025). ECMAScript 2025 Language Specification — RegExp, String.prototype.replace, replacement patterns ($&, $1–$9, $<name>). ECMA-262, 16th edition, June 2025.
- Cox, R. (2007). Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, ...). swtch.com/~rsc/regexp/regexp1.html (canonical reference for catastrophic backtracking).
- Thompson, K. (1968). Programming Techniques: Regular expression search algorithm. Communications of the ACM, 11(6), 419–422 (Thompson NFA construction).
- WHATWG (2025). HTML Living Standard — Web Workers (DedicatedWorkerGlobalScope, terminate-a-worker algorithm). html.spec.whatwg.org/multipage/workers.html.
- World Wide Web Consortium (W3C) (2018). Web Content Accessibility Guidelines (WCAG) 2.1 — Success Criterion 4.1.3 Status Messages. W3C Recommendation 5 June 2018; carried unchanged into WCAG 2.2 (Recommendation 5 October 2023).
These are the original publications the formulas in this tool are based on. Locate them by journal name and year on Google Scholar or PubMed.