Is there a macro to replace white-space in Microsoft Word with adjacent formatting?

by Alexander Dixon   Last Updated April 23, 2018 19:01 PM

Microsoft Word affords the ability to search on formatting type and replace it. 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 boldword and replace it with <strong>bold</strong>. However, there are cases where the document we receive has extraneous white-space in between said formatting. This makes the process of finding and replacing all bold text a bit more tricky. Also, there are cases where a single or multiple white spaces have formatting when they should not.

1.) What is the regex to find and replace all white-space that does not need formatting. The criteria for "does not need" is it cannot be the last white-space on the line, or it cannot be in between two words that require formatting. Essentially, I'm trying to create the cleanest Replace All possible.enter image description here

In the screenshot, you will see the italicized text may have white-space that is not italicized.

Also, in the screenshot, the very last row is bolded throughout, all white-space after the word "Total" should not be bolded.

The macro I'm looking for (or it could just be a regex) will need to be intuitive to some degree.

Related Questions

Update all fields in Word 2010 automatically

Updated July 15, 2015 16:00 PM

Assistance with RegEx in Word

Updated January 20, 2016 12:00 PM

Cache file /home/queryxchang/ could not be written