Skip to main content

Find and replace text

Replace a text fragment in a pasted or imported document.

  • Clipboard
Automate

Enter the source text, search and replacement. Enable regex only for a JavaScript pattern, then run the replacement.

Was this tool useful?

How does this tool work?

Correcting a name in a list, removing a marker or rearranging fields can require more than a simple editor replacement. This page accepts pasted or imported text and produces a new version to review, copy or download. Literal mode suits a specific string; JavaScript regular expressions describe a family of matches. The original file is not changed.

Literal mode replaces every occurrence of the search string. Punctuation is ordinary text: a dot searches for a dot, and $1 inserts the two characters dollar and 1. Matching is case-sensitive by default. Ignore case also finds different capitalisations, using the same replacement text for each.

In regex mode, enter the pattern without surrounding slashes: use \bcat\b, not /\bcat\b/g. Flags have a separate field. g processes all matches; without it only the first is replaced. i ignores case. m changes the behaviour of ^ and $ anchors, s lets the dot match line breaks, and u enables Unicode mode.

Parentheses capture part of a match: $1 inserts the first group, $2 the second and $& the whole match. In regex mode, $$ inserts a literal dollar sign. An empty search is rejected; an empty replacement deletes matches. The counter shows how many replacements occurred, helping you spot searches that are too broad or find nothing.

Processing stays local. Editing an input clears the previous result to prevent copying stale output. Regex patterns run in a Worker stopped after two seconds, so an expensive pattern may be interrupted. No partial result is offered in that case; simplify the pattern or start with an excerpt.

How to use this tool

  1. Provide text and search

    Paste or import your text and enter the search string. Punctuation has no special meaning in literal mode.

  2. Choose the replacement

    Enter new text or leave it blank to delete matches. In regex mode, check captures and flags.

  3. Review and retrieve the result

    Run replacement, review the output, then copy or download it. Editing an input clears the previous result.

Use cases

Standardise wording

Replace an old name throughout a list or a document before publishing it.

Reorder fields

Use captured groups to rearrange matching fragments without typing their contents again.

Remove a pattern

Leave the replacement empty to delete occurrences that match the search.

Examples

Standardise a name regardless of case

The search finds all three capitalisations, but the replacement keeps exactly the case you entered: Lyon. Without Ignore case, only the first occurrence would change and the other two would remain untouched.

Input

Text: Paris, PARIS, paris
Search: Paris
Replacement: Lyon
Mode: literal
Ignore case: yes

Result

Lyon, Lyon, Lyon
3 replacements

Rearrange two capture groups

The first group captures the surname and the second the given name. $2 $1 reverses their positions. This teaching pattern covers ASCII letters only; adapt it for accented names, compound names or apostrophes.

Input

Text: Martin, Alice; Durand, Paul
Pattern: ([A-Za-z]+), ([A-Za-z]+)
Replacement: $2 $1
Mode: regex; flags: g

Result

Alice Martin; Paul Durand
2 replacements

Replace a whole word rather than a fragment

A literal search for cat would also replace the start of catfish, producing dogfish with three replacements. The \b boundaries suit this example; they do not provide linguistic segmentation for every Unicode word.

Input

Text: cat, catfish, cat
Pattern: \bcat\b
Replacement: dog
Mode: regex; flags: g

Result

dog, catfish, dog
2 replacements

Tips and best practices

  • Test a few lines and check the counter before processing a whole document. A regex can be syntactically valid and still target the wrong text.
  • Limits are one million input characters, 10,000 for the search, 100,000 for the replacement and five million for output. Capture-group expansion can hit the output limit even with a modest input.
  • The regex tester helps inspect matches. The text.replace Pipeline operation retains its literal behaviour; regular expressions from this page are not transferred to it.

Sources and references

Frequently asked questions

How do I keep a dollar sign in the replacement?

In literal mode, enter $. In regex mode, $$ inserts a literal dollar sign. Check captures and word boundaries on a small sample before changing a long document.

Is matching case-sensitive?

By default, yes. In literal mode, tick “Ignore case”; in regex mode, add the i flag.

Can I use this in a Pipeline?

The existing text.replace operation performs literal replacement. Regex on this page runs in its time-limited Worker.

How do I replace only the first match?

Enable regex and remove the g flag. Other flags remain available: i ignores case, m changes line anchors, s lets the dot match line breaks and u enables Unicode mode.

Related tools

Tools similar or complementary to this one.

Similar tools

Test a regular expression against text and inspect the matches it returns.

Text & writingFeaturedUse this tool

Remove extra spaces, repeated tabs and empty lines from copied text.

Text & writingFeaturedUse this tool

Convert text to lowercase, UPPERCASE, Title Case or other common case styles.

Text & writingFeaturedUse this tool