Using RegEx to match some text and then everything up to the end of the paragraph sounds, on the face of it, like it should be a fairly thing to do, and in most flavours of RegEx that I’m familiar with (like InDesign’s), it is.
For example, if I want to match all figure captions, I might do something like this:
That is, match “Figure [numbers].” at the start of a paragraph, followed by any larger-than-zero number of any character (
.+), followed by end of paragraph (
$). This works fine in InDesign.
In LibreOffice, however, it always matches only “Figure [number].” and exactly one character (or sometimes no characters at all) after that, regardless of how many characters come after before the paragraph ends. It seemingly ignores the
+ and the
$ entirely. I don’t really see how a RegEx pattern ending in
$ can match a string that ends in the middle of a paragraph, but it does, somehow.
Looking closer, it seems that it’s not actually ignoring
+$ as such; rather, this is to do with formatting. In my case, I’m specifically looking for instances in paragraphs that have the colour red. The pattern that I’m matching on (e.g. “Figure [number].”) happens to also be bold, while the following text is not, but the entire paragraph is red. If I limit the search to red text, however, it seemingly considers the end of the first direct formatting (= where the bold text ends) to be the end of the matchable string.
I recall finding out the hard way before that LibreOffice’s RegEx search works in unexpected ways and applies criteria in a nested way rather than accumulatively, but I would still consider this a violation of RegEx principles: if there is no end of a paragraph in the matchable string, there should be no match – the end of a matchable string is not the same as the end of a paragraph.
Regardless of the cause, is there a way to get past this and actually match a specific pattern plus the rest of the paragraph, specifying formatting for the entire paragraph and ignoring any additional formatting there may be?