Text tools

Find & replace (regex)

Find & replace (regex). Runs entirely on your device, nothing is uploaded.

Runs on your device. The file is never uploaded.

Find & replace (regex) compiles your pattern with the RegExp your browser ships and rewrites every match in a text file. flags defaults to g and replacement to an empty string, so a blank replacement deletes matches. Switch literal on and metacharacters are escaped for you. A pattern RegExp will not compile is reported as invalid regex.

Input

Options

Questions

How do I use capture groups in the replacement?

With dollar-sign references, the same as JavaScript string replace. Write $1 for the first capture group, $2 for the second, and so on, and use two dollar signs to insert a literal one. The replacement field defaults to an empty string, so leaving it blank deletes every match. The pattern field is required and cannot be empty.

What regex flavour and which flags are supported?

JavaScript regular expressions, compiled with the browser's own RegExp, so lookahead, lookbehind, named groups and Unicode property escapes all work exactly as they do in a browser console. The flags option is free text and defaults to g, which replaces every match. Add i for case-insensitive, m for multiline anchors, s to let a dot match newlines, u or v for Unicode mode.

Why did it say my regex is invalid?

Because RegExp refused to compile it, and the tool reports that instead of guessing: "invalid regex" followed by your pattern, your flags and the engine's own message. Unbalanced brackets and a stray backslash are the usual causes, along with an unsupported flag letter. Fix the pattern or turn the literal option on and the same text is matched exactly as typed.

How do I replace plain text without escaping regex characters?

Turn the literal option on. It defaults to off. With it on, every regex metacharacter in your pattern is escaped for you, so a pattern of a dot matches a real dot rather than any character, and something like a version number or a file path can be pasted straight in. The flags option still applies, so keep g there to replace all occurrences.

Why did only the first match get replaced?

Because the g flag was missing from the flags field. Without it JavaScript replaces one occurrence and stops. The default is g, so this usually happens after you have typed something else in there, such as i on its own. Use gi for case-insensitive and global.

Is my file sent anywhere to be processed?

No. Your pattern and your file meet inside a Web Worker in this tab, and neither is transmitted. The tool is per-file, so you can drop a batch and apply the same pattern to all of them, each returned as its own result.

Related Text tools