2

I have lots of text in Microsoft Word similar to the following:

1 The quick brown 2 fox jumps over 3 the lazy dog.

I need some help to find a regular expression that finds the numbers and inserts line breaks before them, resulting in the following format:

1 The quick brown
2 fox jumps over
3 the lazy dog.

I would greatly appreciate anyone's help!

0

1 Answer 1

3

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .