How to add a space after all numbers using Find&Replace?

In my document, I have
1 some text 1 and more 2 and more 3 and more 4.
2 some text
3sometext 1 and more 2 and more 3 and more 4.
4some text

I would like to add a space after the 3 and 4 at the start of a line (without modifying 3 and 4 later, and I’d like to do all the numbers in one Find&Replace. 1 and 2 already have a space after them so don’t need another space.

So far, I use ‘regular expressions’ and ^[1-9] but I’m far from understanding how to use this, so I just did ^1’spacebar’ Replace with 1, then find ^1 and replace with 1’spacebar’, and then the same for 2, etc.

I’d like to know how to do this all at once:

FIND: numbers followed immediately by a letter, and REPLACE: add a space after that number

Or, perhaps an alternative method.

(Also, is there a webpage that has a list of advanced commands for Find&Replace? I’ve read the standard one on LibreOffice but it’s limited for advanced things.)

You have to use parantheses ( ) to tell the regular expression to store, what was found, so you can reference this in replace. As you already had ^[1-9] try

(^[1-9])([a-z])

as search pattern and replace with

$1 $2

so the space between $1 and $2 will be inserted between your two found parts, the digit $1 and the letter $2.

The LibreOffice help page List of Regular Expressions
had a link to the icu-page wich was useful, but now there is (only ?) general talk of the use of the library, no direct help on regular-expressions.

Direct link to the needed part of the icu-doc: Regular Expressions | ICU Documentation

You may check, if it is necessary to improve the regular expression using \p{letter} as the one used above does not even find upper-case and will fail on accented characters.

1 Like

… because using obsolete version of LibreOffice Help (v.6.2) would give you a link to obsolete ICU documentation page (http://userguide.icu-project.org/strings/regexp), which they have changed to https://unicode-org.github.io/icu/userguide/strings/regexp.html since then; and the older link only redirects now to their documentation home page. Using latest help helps :wink:

2 Likes

I don’t know why google prefers to show version 6 when I use my mobile. In this case I opted to search on icu directly to update my post while you wrote your comment… But you save me from checking current help when I’m at my desk…

Here’s another page:

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer