Search code examples
regexwindowsword-2016

Find all semicolons surrounded by numbers in MS Office WORD


In a word document, I'd like to find all semicolons that are surrounded by numbers. so I need the Find/Replace DialogBox to find and select ; in 123;4 and 1;234 (but not example;example or not example; example) .
Please note that in the example above, I just need the semicolon selected for formatting.
I know the basics of RegEx but WORD's so called Wildcards are different. All I could do so far was to find the whole string (eg 123;4) using ([0-9]{1,};[0-9]{1,}) but like I said I only need ; so that I change it's font size, color etc.
Please help. I don't like to spend the whole day on a stupid document.


Solution

  • You can work around Microsoft Word's limitations by inserting a custom sequence of characters to mark the instances of ; that you want to format, and then deleting the custom sequence of characters. In this example I will use the character sequence zzzzz as this likely doesn't appear anywhere else in your document.

    The Process

    First do a find-and-replace:

    Find what: ([0-9]{1,});([0-9]{1,})

    Replace with: \1zzzzz;\2

    Now you can select all instances of zzzzz; and apply the desired format.

    Lastly, do another find-and-replace:

    Find what: zzzzz

    Replace with: nothing