Use RegEx in Word to Mask IP Addresses

Some of my customers get a bit touchy about IP addresses leaving their corporate environment, so they need to be removed before any documents see the outside world. I’ve already added this as a feature in my script that turns a Sonus gateway backup into a DOCX and PDF.

Occasionally I need to send a trace file to a colleague or the vendor, so it needs to be cleansed first. If the addresses aren’t in themselves significant in the interpretation of the file, I generally just open the LOG file in Word and use this quick-and-dirty Find/Replace:




If you want to make the file a little more readable you might want to take a few more steps to retain the device’s own IP, masks and null values:

  1. To retain references to the device’s own IP, find/replace it with something like “<MyIpAddress>”
  2. To retain null/empty IP values (“”), find “([!(1-9)])(” and replace with “\1” followed immediately by a temporary junk value that you’re not going to see elsewhere in the file – maybe “banana”:

  3. To retain (most) masks, find “255.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}” and replace with “<SubnetMask>”
  4. With all of the wanted IPs protected, now use the wildcard at the top of the post to banish any remaining IPs. Find “[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}” and replace with “<IPStripped>”
  5. Now revert “banana” back to “” and you’re good to go!


– G.

Leave a Reply

Your email address will not be published. Required fields are marked *

... and please just confirm for me that you're not a bot first: Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.