Insert paragraph break before numbers

I have a list of questions and answers. All questions begin with a number and I would like to insert paragraph breaks before those numbers.

Using regular expressions, the numbers could be identified by ^[0-9] and for replacement, \n inserts a paragraph. However, I cannot figure out how to specify that the numbers should be retained.

I have looked over the LibreOffice and OpenOffice references and have not found the way to do this. It must not be hard. Perhaps it would be easier if I knew what this property is called.

What you want is a “back reference”, and strangely, it is not covered in the LibO regex help, although it is picked up in the OpenOffice regex wiki. The notation for this has varied with different versions of LibO Writer (I think the regex “engine” changed at some point), and it is different from what one usually uses (and what is described in the link, above). I’m using v., and this is what works for me:

  1. Ensure that you have the "[✓] Regular Expressions" option checked under the “Other options” drop down in the Find & Replace dialog (of course).
  2. For your Search string use: (^[0-9])
    The parentheses are important here, as they define the part of the search you’re going to refer back to.
  3. For your Replace string use: \n$1
    This means:
    • \n = insert new line
    • $1 = insert the value between the first set of parentheses in the “Find” string

So you could see from that, if you had a “Find” of more than one element, e.g.:


and the “Replace” string of, e.g.:


For the text:

Cat in the hat.

Catcher in the rye.

Only the first line would be changed to:

Dog in the bog.

with the $2 part picking out the “middle” regex string from “Find”.

David, Thank you so much. I can’t tell you how helpful this is. The documentation I have read about regular expressions appears to be written for people who already know how to use them. I had read about back references on the OpenOffice Regex wiki, but could not figure out what was being described. Your explanation is the clearest and most helpful that I have seen. Thanks again.
Now I have a similar question but will ask it in another post.