November 10, 2010

Wildcards in MS Word

If you use the Word find and replace feature, it won’t take long before you start to wish for a more powerful way of searching. Using wildcards allows you to do much more flexible and powerful searches, but you need to know the syntax.

For example, I was just editing a manuscript where I wanted to remove the leading zeros from dates and times, such as “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
0([1-9])
and put
\1
in 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:
\1\2

Track changes and find and replace

Find 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.

Some references

No comments:

Post a Comment