For example, I was just editing a manuscript where I wanted to remove the leading zeros from dates and times, for example “September 02, 02:30 p.m.” I began by doing a search for
0[1-9]meaning a zero followed by a digit from 1 to 9. To do an automated replace, I changed the search string to
\1in the replace field, to indicate that I wanted to replace the search string with the first section of the search string in parentheses. This worked on the first date, but then mistakenly found the zeros in “9:03” and “105.” So I added a test to make sure that my zero is not (indicated by “!”) preceded by a colon or a digit. I also put the text before and after the zero in parentheses so that I could replace the search string with everything except the zero. The final search string:
([!:0-9])0([1-9])And the final replace string:
Track changes and find and replaceFind and replace doesn’t behave correctly sometimes when track changes is on. (Some of the characters in the replace string end up in the wrong order.) If I am tracking changes, I will turn off the feature while I do the find and replace, and put a comment on the first piece of changed text explaining what I changed and that it has been done throughout the document.
- For a handy cheat sheet of MS Word wildcards, see: MS Word Pattern Search and Replace.
- A more in-depth reference from a Microsoft MVP: Finding and replacing characters using wildcards. (Thank you, James.)
- An excellent writeup from the Subversive Copy Editor Blog on how to use search and replace: “Spacing Out with Color: Talking Tech with Russell Harper”
- Another nice tutorial on advanced Word search and replace by Tibor Környei at Translators’ Tools.
- “Fun with find & replace: trailing punctuation” from James Harbeck at Sesquiotica: using dummy characters to bold or italicize quotation marks that come after bold or italic text.