Page 1 of 1

Help me write the right regular expression

Posted: Wed Jun 20, 2018 4:23 pm
by loopernow
Hello,

I have a document broken up into passages, with choices for which passage to go to next, like this:

Code: Select all

1
This is the first passage. Turn to whichever passage you want next.

This is the 2nd passage. 2
This passage features clowns. 3
This passage is a mystery. 4

2
Not much to see here.

Go back to the first passage. 1
Clowns? 3
Mystery. 4

3
A gaggle of clowns suddenly erupt from a tiny car, surrounding you with painted grins.
Hopefully you get the idea.

I want to find the numbered passage headings and center them. The issue is that I seem to be able to find numbers followed by a paragraph mark, but not the more specific instances of numbers that are also preceded by paragraph marks. The following regular expression works but is too inclusive; it finds the numbers inside the passages too:

[0-9]{1,3}$

This seems to me to be the right search string to only find the numbered passage headers but doesn't find anything:

$[0-9]{1,3}$

Re: Help me write the right regular expression

Posted: Wed Jun 20, 2018 4:36 pm
by FJCC
A paragraph consisting only of 1 to 3 digits would be
^[0-9]{1,3}$
The ^ indicates the beginning of a paragraph.

Re: Help me write the right regular expression

Posted: Wed Jun 20, 2018 4:39 pm
by loopernow
Yes! I had just found that myself as well. Thank you.

It seems like Writer doesn't search across paragraphs, or something.
In Writer, text appears to be divided into paragraphs. For example x.*z will not match x at the end of a paragraph with z beginning the next paragraph ( x.*z means x then any or no characters then z). Paragraphs seem to be treated separately (although we discuss some special cases at the end of this HowTo).

--from https://wiki.openoffice.org/wiki/Docume ... Office.org