Inserting Non-breaking Spaces Before Units

Have a look at this Word document:

1.png

It is good typographical practice to insert non-breaking spaces before all units. This way units and numbers are kept together when word-wrapping.

Adapt the following syntax to your needs to cover all units in your target text. The Find string covers units before spaces, tabs and line breaks:

(?<=\d+) (?=(A|bar|Hz|min.|minu(ut|ten)|V)(\s|$))

Note the space after the first closing bracket.

In the Replace field you type a non-breaking space (Alt+Space on a Mac). Tick the Regular expression box:

2.png

The exported Word document looks like this:

4.png

Note that –as intended– no non-breaking spaces are inserted at the yellow highlighted positions that don't match with the last part of the regular expression (white space/end of line).

See also: Inserting Non-breaking Spaces Before Numbers

Click here for Information about regular expressions in Java

Tip: On a Mac use Typinator to store your regular expressions.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License