h1

Word: Wildcard find and replace for numbers inside parentheses

July 22, 2018

In a comment on another post (https://cybertext.wordpress.com/2015/07/14/word-wildcard-find-and-replace-for-numbers-and-trailing-punctuation/), AVi asked if there was a way to find percentage numbers (e.g. 56%) that were inside parentheses, and replace them with the same number but without the parentheses — i.e. (56%) becomes 56%.

There is, but it’s a bit trickier than usual because parentheses are also special characters in Word’s find/replace lexicon—these have to be ‘escaped’ for Word to treat them as normal characters and not as special characters.

In figuring this out, I also took into account that there might be single numerals (e.g 4%), triple numerals (e.g. 125%), and numerals with one or more decimals (e.g. 75.997%).

Here’s what I came up with that worked for all those scenarios:

  1. Press Ctrl+H to open the Find and Replace dialog.
  2. Click More, then select the Use wildcards check box.
  3. In Find What, type: ([\(])([0-9]*%)([\)])
  4. In Replace With, type: \2
  5. Click Find Next, then click Replace once the first is found. Once you’re happy that it works, repeat until you’ve replaced them all.

What the find and replace ‘codes’ mean:

The three elements (each is enclosed in parentheses) of the Find are:

  1. ([\(]) — You need to find a specific character (the opening parenthesis), so you need to enclose it in parentheses. However, because parentheses are special wildcard characters in their own right, you need to tell Word to treat them as normal text characters and not as special characters, so you put in a backslash ‘\‘ (also known as an ‘escape’ character) before the (, AND surround this string in square brackets [ ] (otherwise, it won’t work).
  2. ([0-9]*%) — The [0-9] represents any number from 0 to 9; the * represents any more characters immediately after that number (more numbers, or a decimal point), thus not limiting the find to only single digit numbers; and the % symbol says this string of numbers found must finish with that symbol. This finds numbers like 2%, 25%, 283%, 25.4%, etc.
  3. ([\)]) — You need to find the closing parenthesis, so you need to enclose it in parentheses. However, because the closing parenthesis is a special wildcard character in its own right, you need to tell Word to treat it as a normal text character and not as a special character, so you ‘escape’ it with a backslash ‘\‘ before the ), then surround that string in square brackets.

There are no spaces preceding or trailing any of these elements, or in between them, so if you copy the code from this blog post, get rid of any preceding spaces otherwise it won’t work .

For the Replace: \2 — Tells Word to replace the second element of the Find with what was in the Find (i.e. a number followed by a % symbol) .

AVi: I hope this solves your problem. Donations to keeping this blog ad-free gratefully accepted (see the link at the top right of the page).

 

8 comments

  1. ([\ (]) ([0-9] *%) ([\)]) not Work


  2. I wanted to find 1) and replaced by (1) I tried to follow your instructions but failed. Can you help me solve this problem. Watching link: https://youtu.be/5bxUnNDsY1U

    Thank you!


  3. Hi Blu

    Thanks for the video — that helped! I noticed that when you click on one of those numbers, the shading comes on all of them, which means the numbers use auto numbering. A wildcard find/replace will never fix that, as far as I know. But there is an easy way to do it.

    To change how these auto numbers are formatted:
    1. Select the numbered list.
    2. On the Home tab, your auto number icon will show as selected. DO NOT click that one — instead, click the drop-down arrow on the icon immediately to its right, the one for Multilevel List.
    3. Click ‘Define Multilevel List’.
    4. In the ‘Enter formatting for number’, put an opening parenthesis BEFORE the number with the grey shading.
    5. Click OK.
    All your numbers in the selected list should now have an opening parenthesis.

    –Rhonda


  4. I have a file containing multiple choice questions [A, B, C, or D],
    The correct selection is highlighted so I would like to find the correct answer and black out to copy them with your writing then I can Find what: ([A-D]. *. But when there are mathematical formulas then the search as above is not true anymore? Can you help me find the correct answers that contain mathematical formulas?


  5. I want to find any mathematical formula contained in the text, then I must write a wildcard in the find what?


  6. Hi blu

    What you’re asking is way beyond my capabilities. I suggest you go to the Microsoft support forums and ask your question in the Word > Programming group.

    –Rhonda


  7. Can you help me to find any string of characters (<255 characters in length) of this character string in [ ] or ( ) or { }? for example: [This is any string] or (This is any string) or {This is any string of characters}. How do you find wildcards?


  8. Hi blu

    For this find, you’d enter ([\(\[\{]) as a wildcard search. This finds any one of those opening brackets.

    For future reference, if you require specific help on things outside the domain of the post where you make your comment (this is your 6th or so request like this), please contact me privately for my fee to do this work.

    –Rhonda



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: