Go into “Find and Replace”, click on “More > >”, and click “Use wildcards”.
(But you already knew that, right?)
Set “Find what” to {1,9}([0123456789])
Note that the first character is a space, and the second character is {
.
Set “Replace with” to ^p\1
(Caret, lower-case “P”, backslash, “one”)
- The
{1,9}
matches a string of between one and nine spaces.
This allows multiple spaces in the input; e.g.,
1 The quick brown 2 fox jumps over 4 the lazy dog.
[0123456789]
, of course, matches a number (specifically, a digit).
You can probably use [0-9]
instead.
- The
(
…)
delimit a capture group.
We want to capture the digit and ignore the spaces.
^p
, of course, is a paragraph break
(the equivalent of typing Enter).
If you want a line break
(the equivalent of typing Shift+Enter),
use ^l
(lower case “L”).
\1
substitutes the first capture group.
So: find a number, and replace it and the preceding spaces
with itself preceded by a break.
In other words, replace spaces with break before a number.