h1

Word: Find and replace multiple spaces before a number

January 5, 2012

Your document has varying numbers of spaces before a number string — for example, 2, 3, 4 etc. spaces before a number like 85. You want to be able to find all multiple spaces before a numeral and replace them with a single space in one Find/Replace action.

Here’s how to do it.

  1. Open Word’s Find and Replace dialog box (Ctrl+H).
  2. Click More to show more options.

    Find and Replace dialog - click the More button

    Click More

  3. Select the Use wildcards check box.

    Find and Replace dialog - select Wse Wildcards

    Select Use Wildcards

  4. In the Find what field, type: ( {2,9})([1-9])
    Note: There’s ONE space in this text — it’s between the first ( and the {. To be safe, copy the text from Step 4 and paste it into your Find what field.
  5. In the Replace with field, type: <space>\2
    Note: There’s ONE space immediately before the \2, so make sure you type that too. I’ve indicated it with <space>, but you don’t type ‘<space>’ — just press the spacebar instead.

    Find and replace dialog -- make sure you put the spaces in the right places

    Make sure you put the spaces in the right places

  6. Click Find Next to find the next instance of a string of spaces followed by a number. If the Find is successful and you are confident you’re not going to mess anything up, click Replace All. If you want to check each instance before replacing it, just click Replace then Find Next, Replace until you’ve dealt with them all.

Explanation for how this works:

  • ( {2-9}) looks for a space followed by two or more spaces, up to 9 spaces (you can put whatever numbers you like inside the curly braces — if you think you might have some instances of semicolons followed by 15 spaces, then change these numbers to {2-20}, for example. This section is surrounded by parentheses to define it as a separate section.
  • ([1-9]) looks for any numerals. [1-9] says to find any number between 1 and 9 inclusive, and the  parentheses define this as a separate section.
  • The <space> before \2 replaces the multiple spaces found in the first part of the wildcard string with a single space.
  • \2 replaces the second part of the wildcard string with itself. In other words, the numbers found are replaced with themselves, so no change apparently occurs.

You can use this same technique for multiple spaces before any other character — just replace the [1-9] with [A-Z] for any upper case letter, [a-z] for any lower case letter, or [A-z] for any letter whether in upper or lower case (however, Word MVP Graham Mayor says it’s safer to use [A-Za_z] for any upper or lower case letter — see http://www.gmayor.com/replace_using_wildcards.htm).

See also:

[Links last checked December 2011]

6 comments

  1. […] specialists « The saga of this blog’s PayPal ‘Donate’ button Word: Find and replace multiple spaces before a number » Word: Find and replace multiple spaces after a punctuation mark January 4, 2012 […]


  2. […] newsletter/blog of CyberText Consulting – technical communication specialists « Word: Find and replace multiple spaces before a number Word: Find and replace multiple spaces between words January 6, 2012 Your document has […]


  3. […] […]      by Word: Find and replace multiple spaces before a number « CyberText Newsletter January 5, 2012 at 5:30 […]


  4. […] […]      by Word: Find and replace multiple spaces before a number « CyberText Newsletter January 5, 2012 at 5:30 […]



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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: