Word: Find and highlight words of two or more capitals

In one of my Facebook editors’ groups, SB had this dilemma: “[I have a big Word document] listing moth species. Each species entry starts with the species ID number and ends with the old species ID number, which is in brackets. Is there a macro/wildcard I can use to move the final ID number so that it follows the initial one? Both ID numbers vary for each species. Here’s an example:

49.204 Species name 5.5mm Nb. May–Jul. In woods and heaths. Flies in afternoon sun and to light. FP Between spun leaves of Buckthorn or Alder Buckthorn. (1122)

I would like to move the ‘(1122)’ so that it appears immediately after ‘49.204’. There are literally hundreds of species entries and both numbers change for each species.”

What SB wanted was: 49.204 (1122) Species name 5.5mm Nb. May–Jul. In woods and heaths. Flies in afternoon sun and to light. FP Between spun leaves of Buckthorn or Alder Buckthorn.

This one is tailor-made for a wildcard find and replace, but some assumptions must be made first:

  • Assumption 1: The pattern for the current ID number (2 numbers, period, 3 numbers) is consistent
  • Assumption 2: The only parentheses in the paragraph are the ones enclosing the previous ID number
  • Assumption 3: Only numerals are used inside the parentheses. The number of numerals is unimportant (up to 15) but there should be no spaces, no punctuation or other symbols, and no letters within the parentheses.

If all these assumptions are met, then you can use this wildcard find/replace in Word. The usual caveats apply: Test it on a COPY of your document first, and copy/paste the code from this blog post to avoid errors.

  1. Press Ctrl+h to open the Find and Replace window.
  2. Click More to show the checkbox options.
  3. Select the Use wildcards checkbox.
  4. In the Find field, copy this: ([0-9][0-9])(.)([0-9][0-9][0-9])(*)(([0-9]2,15)) (There are NO spaces in this string)
  5. In the Replace field, copy this: 123 54 (Note: There’s only ONE space in this strong, between 3 and 5)
  6. Click Find Next, then Replace.
  7. Assuming it worked as you expected, repeat Step 6 as many times as needed. If you are confident that it does what you want it to do, then click Replace All.

How this works:

  • ([0-9][0-9]): This first element (each separate element is enclosed with parentheses) of the Find looks for a 2-digit number. This first element will become 1 in the Replace.
  • (.): This second element looks for a period (this will become 2 in the Replace). Because it is immediately after the first element, that means that Word will look for two numbers immediately followed by a period.
  • ([0-9][0-9][0-9]): This third element (3 in the Replace) looks for a 3-digit number. Because it is immediately after the second element, Word will look for a period immediately followed by three numbers.
  • (*): This fourth element (4 in the Replace) looks for anything—any number of characters.
  • (([0-9]2,15)): This fifth element (5 in the Replace) is a bit tricky. You start by opening a new element with an opening parenthesis (as for the others above), but you now want to find an opening parenthesis, but you can’t just type it in because a parenthesis is a special character in a wildcard find/replace. You have to ‘escape’ it by typing in front of the opening and the closing parentheses of the string you want to find. The rest of this element comprises any number (the [0-9] part) that’s between 2 and 15 characters long (the 2,15 part.
  • In the Replace, you rearrange the elements into the order you want them, and add any spaces or other punctuation you need. So, 123 54 means that the first three elements remain the same as they were (in the example, that’s 49.204), then there’s a space, then the fifth element (in the example, that’s (1122)), then all the characters that make up the fourth element.

I’m sure this find/replace string could be improved, but it was what I came up with in a few minutes. And it solved SB’s problem and saved her a LOT of time as she had hundreds of these to do.



Leave a Reply

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