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:
- Ensure that you have the "
[✓]
Regular Expressions" option checked under the “Other options” drop down in the Find & Replace dialog (of course).
- 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.
- 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”.