Word: Insert a space between a number and a letterFebruary 8, 2012
A document I edited the other day was peppered with hundreds of values followed immediately by the unit of measure (e.g. 5km, 20mm, 50m/s etc.). Our house style follows the Australian Style Manual, which is to have a space between almost every value and its unit of measure (e.g. 5 km, 20 mm, 50 m/s).
While I could run several find and replace (F/R) passes looking for various measurement units (e.g. km) and then replacing them with a space followed by the measurement unit, there were a LOT of different units used and some, such as ‘m’ for meter, weren’t easy to catch using the normal F/R methods — either that, or I caught more than I wanted and ended up with two spaces in front of any word starting with ‘m’. Doing 20+ passes of F/R hoping to get most of the measurement units didn’t seem like a lot of fun.
So I applied some of the knowledge I’ve learned recently about wildcard F/R to catch them all. I still had to replace them one at a time as I needed to avoid adding a space between legitimate instances of numbers followed by a letter (e.g. chemical symbols such as H2S). But using the wildcard search made it much easier to find every instance of a number followed immediately by a letter, and replace the relevant ones with the same number followed by a space then the same letter.
- Open Word’s Find and Replace dialog box (Ctrl+H).
- Click More to show more options.
- Select the Use wildcards check box.
- In the Find what field, type: ([0-9])([A-z])
- In the Replace with field, type: \1 \2
Note: There’s ONE space immediately after the \1, so make sure you type that too.
- Click Find Next, then click Replace to insert a space into each one that’s relevant. Repeat until you’ve done them all.
Explanation for how this works:
- ([0-9]) looks for any numeral. This string defines the first section of the Find. Because you are using wildcards, you need to surround the characters you want to find in parentheses. The square brackets indicate a range — in this case any numeral from 0 to 9 will be found.
- ([A-z]) looks for any letter, upper or lower case. This string defines the second section of the Find. Again, you define the range of letters to be found with square brackets; the [A-z] means any upper case letter from A through the lower case letters to z.
- \1 replaces the first part of the wildcard string with itself. In other words, the numeral found is replaced with itself, so no change apparently occurs.
- The single space after \1 replaces adds a space between the two parts found.
- \2 replaces the second part of the wildcard string with itself. In other words, the letter found is replaced with itself, so no change apparently occurs.
However, what I couldn’t figure out how to do was make the space I inserted a non-breaking space. In a normal F/R, I’d use ^s for a non-breaking space, but I couldn’t figure out how to add that successfully to the Replace field. Anything I tried just put in ^s or (^s) as text, NOT as a non-breaking space. Anyone know how?
[Links last checked August 2012]