Regex find and replace
Regex find and replace edits a whole document in one pass. Type a pattern and a replacement, use $1 and $2 for capture groups, and turn on case-sensitive or whole-word matching; the match count updates as you type. All processing runs locally in your browser.
Input text
Result
FIND & REPLACE
How it works
In plain mode, the search text is escaped and matched literally using a JavaScript RegExp with the global and Unicode (u) flags. In regex mode, the pattern is used as-is, with the u flag when the pattern is valid with it. The case-insensitive flag is added unless Case sensitive is enabled. The whole-word option skips a match that has a letter, digit or underscore, in any script, directly before or after it. For a pattern that runs without the u flag, only A to Z, a to z, 0 to 9 and _ count as word characters. String.replace() with the RegExp applies the substitution across the entire input on every keystroke. In regex mode that work runs in a background Web Worker and is stopped after 2 seconds. All processing runs in JavaScript in your browser.
Processing runs in your browser
All processing happens locally in your browser tab. Our servers are not involved at any point.
Related operations
For more advanced pattern matching, try the regex tester. To alphabetise or dedupe the result, use sort lines. For comparing two versions of the text side by side, see text diff.
Frequently asked questions
- How do I use capture groups in the replacement?
- In regex mode, you can reference capture groups from your pattern using $1, $2, etc. in the replacement field. For example, to swap 'first last' to 'last, first': pattern (\w+) (\w+), replacement $2, $1.
- What regex flavor does this tool use?
- This tool uses JavaScript's built-in RegExp, which is based on the ECMAScript standard. It supports most common regex syntax including character classes, quantifiers, groups, lookahead, and lookbehind (in modern browsers). Patterns run with the Unicode (u) flag, so . matches a whole emoji and \p{L} matches a letter in any script. A pattern that is only valid without the u flag, such as \- outside a character class, runs without it.
- What does the 'g' flag do?
- The global flag (g) replaces all matches in the text. Without it, only the first match is replaced. This tool always applies the global flag in regex mode so all occurrences are replaced.
- What happens if a pattern is too slow?
- Regex mode runs in a Web Worker. A pattern that takes longer than 2 seconds, for example one with catastrophic backtracking such as (a+)+$, is stopped with a message instead of freezing the tab. Live preview in regex mode pauses for input over 200,000 characters.
Last reviewed September 30, 2026
Other pages for this tool
Related tools
- Background reading: Complete guide to text tools
- Step by step: Extract and clean up text from a PDF