Ask Your Question
0

Regular Expressions not working as expecting: remove a line

asked 2016-10-17 13:50:14 +0200

MatthijsG gravatar image

updated 2016-10-17 13:50:34 +0200

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

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
1

answered 2016-10-17 18:17:31 +0200

updated 2016-10-17 18:18:42 +0200

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.*
edit flag offensive delete link more

Comments

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.

PhLo gravatar imagePhLo ( 2018-12-04 05:29:54 +0200 )edit
0

answered 2016-10-17 22:01:08 +0200

RGB-es gravatar image

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.

edit flag offensive delete link more
0

answered 2016-10-18 10:41:40 +0200

pierre-yves samyn gravatar image

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

edit flag offensive delete link more
0

answered 2016-10-17 14:19:37 +0200

erAck gravatar image

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

edit flag offensive delete link more

Comments

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

rautamiekka gravatar imagerautamiekka ( 2016-10-17 18:13:32 +0200 )edit

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

erAck gravatar imageerAck ( 2016-10-18 15:04:59 +0200 )edit

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.

rautamiekka gravatar imagerautamiekka ( 2016-10-18 15:37:23 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-10-17 13:50:14 +0200

Seen: 202 times

Last updated: Oct 18 '16