# 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.

edit retag close merge delete

Sort by » oldest newest most voted

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 Regular-Expressions.info link, above). I'm using v. 6.0.1.1, 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.:

(^Cat)(.*)(hat\.$) and the "Replace" string of, e.g.: Dog$2bog.

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".

more