Microsoft Word affords the ability to search for formatted text and to replace it and the formatting. This feature is great in my line of work, where I have to convert Word documents into online surveys. A simple example would be to find a
bold word and replace it with
However, there are cases where the document we receive has extraneous, unformatted, white-space in between said formatting. This makes the process of finding and replacing all bold text a bit trickier. Also, there are cases where white-space has formatting applied when it shouldn't.
What is a macro, or wildcard (regex) search/replace, to find and replace all white-space with incorrect formatting with the correctly formatted white-space?
Two criteria for "incorrectly" is that the last white-space on the line must be unformatted, and white-space in between two formatted words must be formatted. Essentially, I'm trying to create the cleanest Replace All possible.
Take the following screenshot as an example:
The pink/purple highlights represent white-space that is normal style, but should be italicized.
The red/orange highlight represents white-space that is bolded, but should be normal, un-bolded style.
In both cases, I would need the macro, or wildcard find/replace, to know to convert one to italic, and remove the bolding style altogether from the other.
To further expound:
Currently, if I do a find and replace all by only leveraging Microsoft Word's font style format, it results in three
<em> elements in some lines, e.g.:
<em>The average American expects the rate of deflation (opposite</em> <em>of</em> <em>inflation)</em> will be between 0% and 2%
The ideal result would be one
<em>The average American expects the rate of deflation (opposite of inflation)</em> will be between 0% and 2%
(Note that I use italic and bold as examples, but the same could be said for underline text as well.)