Back to Tools

Ultimate Regex Find & Replace

Perform complex text transformations using capture groups and advanced substitution patterns

PRO TRANSFORMATION
Source Text
Side-by-Side Comparison
Original

                        
Transformed

                        

Find and replace with patterns instead of fixed words

An ordinary find-and-replace can swap one word for another. A regex find-and-replace can reorder names, wrap numbers in tags, strip trailing whitespace or reformat dates across thousands of lines in one pass. This tool applies your regular expression to the text you paste, substitutes the replacement string and shows the original and the transformed version next to each other, so you can check the outcome before copying it anywhere.

Running a replacement

  1. Enter your expression in Find (Regex Pattern). The default is a two-word pattern with two capture groups.
  2. In Replace With, write the substitution. Use dollar-number references such as $1 and $2 to insert what each capture group matched. The default is a reordering that puts the second word first, then a comma, then the first.
  3. Set Flags. The box starts with g, i and m, meaning global, case-insensitive and multiline. Remove any you do not want.
  4. Paste text into Source Text, or click Sample to load three sample names. Paste reads your clipboard and Clear resets it.
  5. Click Transform Text Now, then use Copy Result on the Side-by-Side Comparison panel.

What you will see

Badges show how many matches were found and that the run succeeded. The left pane, labelled Original, keeps your input untouched, while the right pane, Transformed, shows the output. An invalid pattern raises an alert with the engine's error message.

Practical examples

  • Convert a list of names from first-last to last-comma-first for an import file.
  • Collapse runs of spaces or blank lines in text copied from a PDF.
  • Wrap every number in a bracket pair before pasting into a document.
  • Rename variables in a snippet by matching a prefix and reusing the remainder through a group.

Details worth knowing

Replacement strings follow JavaScript rules, so $1 to $9 refer to capture groups, $& inserts the whole match and a double dollar sign yields a literal dollar sign. If you leave g out of the flags, only the first match is replaced. The replacement count shown equals the number of matches found, which is only accurate when the g flag is present. Without it, only one substitution happens even though the pattern might occur several times.

Special characters in the Find field are regex syntax, so a literal dot, bracket or plus must be escaped with a backslash. Work on a copy of important text, because the tool changes nothing in your source box but you will paste the result over something eventually. Everything runs as JavaScript in your browser.


Related Tools

Related Tools


Frequently Asked Questions

How do I reuse part of the matched text in the replacement?
Wrap that part of the pattern in parentheses to make a capture group, then refer to it as $1, $2 and so on in the Replace With field. For example, replacing (\w+) (\w+) with $2, $1 swaps two words around.
What do the default flags g, i and m mean?
g replaces every match instead of just the first, i ignores upper and lower case, and m makes the caret and dollar sign match at the start and end of each line. You can edit the Flags box freely to remove or add flags.
Why is only the first match replaced?
The g flag is probably missing from the Flags field. Without it the engine stops after the first match. Add g and run the transformation again. The match counter also assumes global mode, so it may overstate replacements without it.
How do I insert a literal dollar sign in the replacement?
Write two dollar signs in a row. A single dollar sign followed by a digit is treated as a group reference, and a dollar with an ampersand inserts the entire match, following standard JavaScript replacement rules.
Can I undo a replacement?
Your original text stays in the Source Text box and in the Original pane, so nothing is lost. Adjust the pattern or replacement and click Transform Text Now again. Only copy the Transformed output once it looks right.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.