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
- 1Paste or type your text into the input panel on the left.
- 2Type your regex body into the Pattern field, no surrounding slashes.
- 3Type the substitution into Replace. Use
$1,$2etc. to insert capture groups. - 4Pick a preset from the Flags dropdown:
g,gi,gm, orgim. - 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 F | Open the find & replace panel inside the input Plus |
| Ctrl Z | Undo the last input change |
| Ctrl Shift Z | Redo |
| Ctrl Shift Enter | Toggle fullscreen focus on the editor Plus |
| Esc | Close find & replace, or exit fullscreen |
| Ctrl K | Open the command palette to jump to any tool Plus |
| Ctrl S | Save current workflow draft Plus |
| Ctrl P | Run 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, $& 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.
user_42 logged in at 09:14 user_103 logged in at 09:15
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, $&, $`, $', $$. |
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?
\d+ not /\d+/. The flags are picked from the Flags dropdown.How do I reference a capture group in the replacement?
$1, $2, and so on. $& inserts the whole match. $$ inserts a literal dollar sign.My pattern is showing [invalid regex]. What do I do?
[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?
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.