Regular Expressions not working as expecting: remove a line

When doing a Search&Replace with regular expressions, the following search removes a complete blank line (=only an enter)

^$

I’ve to Search&Replace often text like ‘label foobar: #N/A’. Therefore, i use

 ^.{0,99}#N/A$ 

This expression removes the unwanted text, but doesnt remove the line.

And my question is, why not?

In the first case, the preview highligts the whole line. With the second code, only 'till the enter-mark

Tried, at least by what I know about RegEx, you can’t delete the newline with a RegEx. Tested expressions in LO 5.2.2.2:

asd\r
asd\r\n
asd\n
asd.*\r
asd.*\r\n
asd.*\n
asd\r.*
asd\r\n.*
asd\n.*
asd.*\r.*
asd.*\r\n.*
asd.*\n.*

Yay, Finland. Writer’s regular expression support is abysmal at best, at least in regards to new line characters. I’m encountering this problem now, and it’s very annoying.

The ^$ empty sequence is a special case expression. In all other expressions the ^ and $ are anchors to the expression.

^$ is supposed to mean empty line. If it doesn’t it’s violation of the standard.

But ^something$ is something different. What standard btw?

RegEx is mostly identical between implementations, with Perl’s being the sanest. Without checking I don’t know if there’s an actual standard shown to the authorities, but not everything’s been standardized that way.

Just to add a bit of information: RegExp on Writer only work within a paragraph and that’s why you cannot select part of the text and the paragraph end.

You may try with AltSearch extension, which offers more functionality than the default LibO S&R tool.

Hi

As @RGB-es said you can do this with AltSearch extension:

  • search for: ^.+#N/A$\p
  • replace with nothing

AFAIK it is not possible to do it without the extension in one shot. You have to:

  1. Replace empty paragraphs with a text that is not in the document (e.g. µLIBOµ)
  2. Replace ^.+#N/A$ with nothing (you get new empty paragraphs)
  3. Replace empty paragraphs with nothing
  4. Replace µLIBOµ with \n (recreate the “good” empty paragraphs)

Regards