Regex replace

Regex replace runs your regular expression against pasted text and swaps every match with the replacement string. The pattern is parsed as a JavaScript RegExp, so \d, \w, (group), and backreferences like $1 all work the way the JS spec defines them. Pick from four flag presets in the dropdown. Need plain literal swap instead? Use find and replace.

Input
Line 1:1 LF cloud_done Saved locally
Result Regex Replace
0 lines 0 chars

JavaScript regex against your pasted text

The Pattern field is the body of a JavaScript regular expression, no surrounding slashes needed. Replace is the substitution string and supports the standard JS replacement tokens: $1 through $99 for numbered capture groups, $& for the whole match, $` for the text before the match, and $' for the text after.

The Flags dropdown picks one of four presets: g (global), gi (global plus case-insensitive), gm (global plus multiline, so ^ and $ match line starts and ends), and gim (all three). Global is always on so every match is replaced. If your pattern is invalid, the output panel shows [invalid regex] followed by the engine error message instead of the result, so you can fix it.

For literal-string replacement without metacharacter handling, use find and replace. To extract the matches as a list rather than replace them in place, use extract regex matches.

How to use regex replace

  1. 1Paste or type your text into the input panel on the left.
  2. 2Type your regex body into the Pattern field, no surrounding slashes.
  3. 3Type the substitution into Replace. Use $1, $2 etc. to insert capture groups.
  4. 4Pick a preset from the Flags dropdown: g, gi, gm, or gim.
  5. 5Read the result on the right; if the pattern is invalid you will see [invalid regex] with the engine error.

Keyboard shortcuts

Drive TextResult without touching the mouse.

Shortcut Action
Ctrl FOpen the find & replace panel inside the input Plus
Ctrl ZUndo the last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor Plus
EscClose find & replace, or exit fullscreen
Ctrl KOpen the command palette to jump to any tool Plus
Ctrl SSave current workflow draft Plus
Ctrl PRun a saved workflow Plus

What this tool actually does

Native JavaScript RegExp engine

The Pattern is fed straight to new RegExp(pattern, flags), so character classes, quantifiers, lookaheads, lookbehinds (where the browser supports them), and Unicode property escapes all behave as documented on MDN.

Replacement tokens are supported

Replace uses JavaScript replacement syntax. $1 inserts the first capture group, $&amp; the whole match, $$ a literal dollar sign, and $` / $' the text before / after the match. Named groups via $<name> work where the engine supports them.

Four flag presets, global always on

The Flags dropdown locks you into g, gi, gm, or gim. Global is non-negotiable so every match in the input is replaced. Add case-insensitivity with gi, line-anchored mode with gm, or both with gim.

Errors are visible, not silent

A bad pattern (unbalanced parens, dangling quantifier, etc.) renders as [invalid regex] <message> in the output panel. Fix the pattern and the result reappears on the next keystroke.

Empty pattern is a no-op

If Pattern is empty the input passes through verbatim. There is no accidental match-everything behaviour. Add at least one character to start replacing.

Worked example

Pattern user_(\d+) logged in at (\d{2}:\d{2}), replace user #$1 at $2, flags g. The two capture groups feed back into the substitution.

Input
user_42 logged in at 09:14
user_103 logged in at 09:15
Output
user #42 at 09:14
user #103 at 09:15

Settings reference

Behaviour Effect on output
Pattern Body of a JavaScript regex. No surrounding slashes. Empty value passes input through unchanged.
Replace Substitution string. Supports $1-$99, $&amp;, $`, $', $$.
Flags = g Global. Every match in the input is replaced.
Flags = gi Global plus case-insensitive. API and api both match.
Flags = gm Global plus multiline. ^ and $ anchor at the start and end of each line.
Flags = gim Global, case-insensitive, multiline. All three at once.
Invalid pattern Output reads [invalid regex] followed by the engine message until the pattern is fixed.

FAQ

Do I include the surrounding slashes?
No. Type only the body. \d+ not /\d+/. The flags are picked from the Flags dropdown.
How do I reference a capture group in the replacement?
Use $1, $2, and so on. $&amp; inserts the whole match. $$ inserts a literal dollar sign.
My pattern is showing [invalid regex]. What do I do?
The browser engine rejected your pattern. Look at the message after [invalid regex]; common causes are unbalanced parentheses, dangling quantifiers, or unsupported lookbehinds in older browsers. Fix and the result reappears.
Can I do a non-global, single-match replace?
Not directly. The four flag presets all include g. If you only want to replace the first match, use find and replace with a unique search term, or shape your pattern so it only matches once.
Does this hit a server?
No. The replace runs against the JavaScript regex engine in your browser. The text and pattern stay on your device.