Help me write the right regular expression

Discuss the word processor
Post Reply
loopernow
Posts: 2
Joined: Wed Jun 20, 2018 4:12 pm

Help me write the right regular expression

Post 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}$
OpenOffice 4.1.5 on Windows 10
FJCC
Moderator
Posts: 9231
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help me write the right regular expression

Post by FJCC »

A paragraph consisting only of 1 to 3 digits would be
^[0-9]{1,3}$
The ^ indicates the beginning of a paragraph.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
loopernow
Posts: 2
Joined: Wed Jun 20, 2018 4:12 pm

Re: Help me write the right regular expression

Post 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
OpenOffice 4.1.5 on Windows 10
Post Reply