Skip to content

Find & replace in Word

Replace text throughout a .docx without opening Word.

Updated

Add your files

DOCX

How to find and replace in a Word document

  1. 1

    Add one or more .docx files; the same replacement runs through all of them.

  2. 2

    Type the text under Find and what should take its place under Replace with. Switch on Match case to tell "Invoice" from "invoice", and Treat as a regular expression to match a pattern instead of exact text.

  3. 3

    Press Find and replace. Each file comes back with -updated added to its name, and the result counts the replacements and the files.

Plain text or a pattern

With Treat as a regular expression off, the Find text is matched exactly as typed and Replace with is inserted as typed. With it on, Find is read as a JavaScript regular expression, so \d{4} matches any four digits and colou?r matches both spellings; an expression that will not compile stops the run with a message. The replacement is always literal text, so $1 is written as those two characters rather than a captured group. With Match case off, upper and lower case match alike in both modes, and an empty Find field stops the run.

How Word stores text, and why it matters

Word splits a sentence into runs wherever the formatting changes, and often where it does not, so a search inside each run on its own misses a phrase that straddles two of them. Here the runs between one tab, line break, picture or field and the next are joined into one stretch and searched together; when a match spans several runs, the replacement goes into the first and the rest of the match is cut from the others, which keep their own formatting. The edit is made in the document XML and the file is repacked, so a match in a header, footer, footnote, endnote or text box is replaced the same way as one in the body.

Questions about Find & replace in Word

Does it keep the formatting?

Yes. The file is not rebuilt: only the runs of text that a match spans are edited inside the original document, and the replacement takes the formatting of the run where the match starts. Styles, pictures, tables, headers, footers, comments and everything else stay exactly as they were.

Why was my text not found?

A match has to lie within one stretch of text: it cannot cross a tab, a line break, a picture or a field such as a page number, and the search runs paragraph by paragraph, so a phrase that continues into the next paragraph is not found. Check the spelling, switch off Match case, and when the text contains characters such as dots or brackets, keep Treat as a regular expression off so they are taken literally.

Which parts of the document are searched?

The body, every header and footer, footnotes and endnotes, including text inside text boxes. Comments, the document properties and words inside pictures are not. When nothing matches in any file, the run stops with a message; when another file in the run had matches, a file without any is still written out unchanged.

Advertisement