Software optimize

Avoid a Word Find and Replace gotcha that could prove catastrophic

Here's a Find and Replace gotcha that you might not uncover until it's too late. Awareness is the best way to avoid it, so make a note of it.

Word's Find and Replace feature lets you alter multiple instances of a word or phrase at the same time. However, one thing you might not consider is space characters - and they matter.

Let's look at a quick example. In the document below, I have two short sentences. If you can't read the figures, the sentences follow:

You'll receive a certificate at the end of your class. It is notification of your participation. However, it isn't official without a notarized signature, so please make sure to stop on your way out and have the certificate notarized.

Now, let's change all occurrences of is not to isn't. A quick find and replace should do the trick, right? Let's see what happens when we ignore spaces:

  1. Click the Home tab and then click Replace in the Editing group. In Word 2003, choose Find and Replace from the Edit menu.
  2. In the Find What control, enter is not.
  3. In the Replace With control, enter isn't.
  4. Click Replace All and then OK. The results might not be what you expected.

The replace task found one occurrence of is not and replaced it with isn't, correctly. However, it also found is notification and changed it to isn'tification - that's a mistake.

Being mindful of space characters will eliminate these types of unexpected errors. In this case, following the search string (in the Find What control) with a space character will eliminate the inappropriate find, but be careful because doing so will introduce a new error as as shown below.

You must enter a space character after is not in the Find What control and after isn't in the Replace With control to get the desired results.

When this happens, there's no warning that the feature hasn't understood your intentions. The only way to avoid this behavior is awareness. Running a spell check will find most errors of this type, but you can't depend on that. To the feature, a space character is another valid character. Including them in your search and replace strings is the best way to avoid trouble.

Keep in mind that the space characters that occur before the find and replace strings are just as important.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

37 comments
Thomas Moser
Thomas Moser

Run grep on a plaintext version of the document first and see if there are any pitfalls before you go the global replace. Too bad MS does not show a result summary ala Dreamweaver.

tclguru
tclguru

Told to me by someone who swears it is true. A book company was about to publish some Harlequin Romance-type novel, and an editor decided that a certain character David should be renamed Jeff, so a global search and replace was done. The book was published, and some readers were puzzled by a scene in which two characters discuss the merits of Michaelangelo's Jeff.

tclguru
tclguru

Told to me by someone who swears it is true. A book company was about to publish some Harlequin Romance-type novel, and an editor decided that a certain character David should be renamed Jeff, so a global search and replace was done. The book was published, and some readers were puzzled by a scene in which two characters discuss the merits of Michaelangelo's Jeff.

ABERZO
ABERZO

Thank you, Ms. Harkins, for a very useful tip; once it gets explained one wonders why one never thought about it... Thanks again.

denisehenry
denisehenry

Also, what you are searching for might be at the end of a sentence and not be followed by a space. Sometimes, even though it is a little more time consuming, the more thorough option is to do the search and replace where you find each instance and get to choose replace or find next item. Alt-F will find the next item; Alt-R will replace the current selection and move to the next item. It is easy to have your hand on the ALT and alternate as needed between the F and the R. And, as others have mentioned...proofreading is essential. One project I worked on where someone had taken a scanned document and ran it through OCR. They only proofread the part that was changed. My boss found several errors and sent it back. I ended up taking it home and reading through it. Good thing - instead of a Responsible Party - we had a Responsible Panty!

stephenmj
stephenmj

A couple of years ago, we had a very embarrassing mistake is a final report that was issued to a client. We specialize in machinery rotordynamics and the project had to do with investigations into a gas turbine disk failure. Overall the work was well done and the client appreciated our work. I don't think clients ever read a report completely, because it was months before we ourselves caught this mistake - "Excessive stress and high temperatures resulted in the dick failure." Can't blame and the spelling/grammar check tool; no spelling mistakes and nothing wrong in it grammatically :-)

thiers
thiers

If you enclose 'is not' with < and > to indicate beginning and end of words (i.e. ) you can disregard the spaces. You just have to remember to check the box Use Wildcards before doing the search and replace

OldGuru
OldGuru

It works in most editors, even in simple text editors, but apparently not in Word from mighty Microsoft. I doesn't allow you to use that checkbox if the search term includes more than one word. May be that's why it's called "Word" and not "Words"!

OldGuru
OldGuru

to deal with this problem that works regardless of the position of the search term and whether or not it's always preceded or followed by a space in the text. Just check "Find whole words only" checkbox.

Kent Lion
Kent Lion

When you "replace all" in Excel, there is an extended option telling Excel to apply the replacement to the current worksheet or to the whole workbook. If the extended option is set to "worksheet", and you first select an area on that worksheet, the global replacement is restricted to within the selection (as desired and expected). The gotcha is, if the extended option is set to "workbook", replace all will extend to the entire workbook, even if an area is selected, and you will have not necessarily have any indication that you've just replaced outside of your selection. Since the "workbook" option is not automatically reset after a replace operation, if you replace something a half hour later, you may not remember that you've told Excel to ignore selections. To make matters worse, as soon as you save or use a form control in Excel, you can no longer Undo that global replace.

maj37
maj37

This is not a new problem with Word it is an issue with any editor that has search and replace. I learned years ago to be very careful with search and replace and to check the results afterwards. maj

premiertechnologist
premiertechnologist

There is no way to pre-edit entries here; there's no preview. So folks, get it right the first time. To recap what I just said: They're isn't way too predit entrieshere; theirs no preveuw. So fokes, ged it rite the furst tighm. Find and replace. Bah! Not even a spel cheker.

Geosync
Geosync

Good example, Susan. I have encountered many others along the way, too. For this reason, I now refer to 'Find and Replace' as 'Search and Destroy!' :)

sparent
sparent

If I decided that a Find and Replace is quicker than doing it manually, I will usually follow up with a Find of the resulting string to make sure that I have not created mistakes such as presented above.

Shadeburst
Shadeburst

The idea of doing a global find and replace is to save time. When you're dealing with a very large document containing numerous instances of the Find string, then you're just going to have to get lazy and use the Replace All option. Follow up with a Spell Check. But if there are few instances, then you will probably SAVE time by replacing individually. No time invested in thinking up a bulletproof method, no time wasted undoing the errors.

nieldc
nieldc

This should be replaced with "isn't." but because there is no space at the end this case will also be skipped.

NickNielsen
NickNielsen

One of the first things I discovered when I first started using Word (6, I think): Find & Replace does exactly what you tell it to do, even if that's not what you want it to do. I have since become adept at formatting my find criteria so as to prevent problems like this, but I still get caught sometimes..

ssharkins
ssharkins

Find and replace and spellcheck are only part of the routine -- you still have to spend time proofing your document with human eyes!

Mark.Mathews
Mark.Mathews

I'm curious why this works for "is not." but skips the instance of "is notification".

ssharkins
ssharkins

Anotherhelpful hint -- thank you!

Mark.Mathews
Mark.Mathews

I tried this as you suggested but the check box for "Find whole words only" was grayed out. Apparently it only works for single words (like "is" or "not") but not multiple words (like "is not"). Please let me know if I'm wrong.

ssharkins
ssharkins

Thanks for the warning -- well worth knowing!

mirossmac2
mirossmac2

I unpacked my Exidy Sorcerer in 1980-ish and set about word-processing my latest novel - economizing by typing a mere time-saving e for every occurrence of Elizabeth. Search/Replace gavElizabeth mElizabeth a vElizabethry unrElizabethadablElizabeth chaptElizabethr . A great tutorial on my first outing!

NickNielsen
NickNielsen

that doesn't have a spell checker? If it's that big a deal, draft your post in MSWord or OO/LO Write, spell check, save as text, then cut and paste. Your spelling will be correct, and the save as text will strip out those high-order characters that give the forum software fits.

ssharkins
ssharkins

Don' be so hard on the feature! ;) Find and Replace is your friend -- even if it does bite you occasionally! :)

ssharkins
ssharkins

I like this -- sa search for the string itself -- so you can review what actually happened -- a great idea!

ssharkins
ssharkins

You should always follow and Find & Replace task (a large one) with a spellcheck. You'll catch errors and learn these gotchas so you can avoid them in the future.

PatriciaT
PatriciaT

In this case, you could do two replacements, one including a space in the FIND WHAT field, and a second tine including a period instead of a space.

mirossmac2
mirossmac2

the search string is not[. ] would find is not followed by either a stop or a space.

AnsuGisalas
AnsuGisalas

It was a digest of text, but the parser was bleeding its own tags into the digest... Luckily the number of tag forms was limited, and it was easy to formulate a search-replace to nuke them out of existence. Takes a while for it to go through 6000 replacement targets, but not prohibitively long. Three tags of over 6000 instances, two of around 1000.

santeewelding
santeewelding

Writing and proofing went out with "processor" and "processing".

cdiamond
cdiamond

comma, semicolon, colon . . . Try 2 searches. The first with a space afterwards. The second with a space before but without replace all. You will then need to use your cheaper more powerful computer to decide whether to change.