Ultimate Regex Find & Replace
Perform complex text transformations using capture groups and advanced substitution patterns
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
- Enter your expression in Find (Regex Pattern). The default is a two-word pattern with two capture groups.
- 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.
- Set Flags. The box starts with g, i and m, meaning global, case-insensitive and multiline. Remove any you do not want.
- Paste text into Source Text, or click Sample to load three sample names. Paste reads your clipboard and Clear resets it.
- 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