Author Topic: How can I remove empty lines ?  (Read 3503 times)

jcelle

  • Senior Community Member
  • Posts: 233
  • Hero Points: 5
How can I remove empty lines ?
« on: November 02, 2017, 09:39:36 am »
Hello,
I would like to remove empty lines and tried a replace of regular expression "^$" by "".
Quotes are for understading only, I don't type them, which means that the replace field is empty.
Problem is that apparently Replace utility does not allow to trigger a replace if you leave this field empty.
I searched this forum with the phrase I have put in the subject and I get results for 'empty', 'remove'...
Thanks for any advice you could give !
Cheers,
Jerome

Marcel

  • Senior Community Member
  • Posts: 261
  • Hero Points: 26
Re: How can I remove empty lines ?
« Reply #1 on: November 02, 2017, 03:18:21 pm »
How about something like that
Code: [Select]
\n\s*\n  => \n

jcelle

  • Senior Community Member
  • Posts: 233
  • Hero Points: 5
Re: How can I remove empty lines ?
« Reply #2 on: November 03, 2017, 07:58:26 am »
Gee !
Thanks that is working  :D !

Note that I did not know (and still don't know) what \s stands for, so I wen to SlickEdit help page about Regular Expression and found this interesting page (attached as screenshot) where it is stated that it should be possible to replace ^\R by "leave the field blank", which I tried and then worked...
It is strange that the ^$ combination does not work; I mean SlickEdit finds newlines through ^$ but does not allow replacement.  ???
« Last Edit: November 03, 2017, 08:04:52 am by jcelle »

TKasparek

  • Senior Community Member
  • Posts: 245
  • Hero Points: 29
Re: How can I remove empty lines ?
« Reply #3 on: November 03, 2017, 03:26:55 pm »
Assuming you're using the Perl regular expressions, SlickEdit uses [something very close to] PCRE [in terms of use]. I find this to be helpful: https://www.debuggex.com/cheatsheet/regex/pcre
« Last Edit: November 03, 2017, 05:59:38 pm by TKasparek »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6455
  • Hero Points: 503
Re: How can I remove empty lines ?
« Reply #4 on: November 03, 2017, 04:04:06 pm »
SlickEdit does not use PCRE. It's a very close implementation though but only from a syntax and feature perspective.

The give away is that SlickEdit supports variable length look behind (a pain to implement) and PCRE (and Perl) definitely do not.

joecar

  • Senior Community Member
  • Posts: 385
  • Hero Points: 9
  • engineer/gearhead
Re: How can I remove empty lines ?
« Reply #5 on: November 03, 2017, 05:04:54 pm »
...
Note that I did not know (and still don't know) what \s stands for,
I too would like to know what \s means.

Quote
so I wen to SlickEdit help page about Regular Expression and found this interesting page (attached as screenshot) where it is stated that it should be possible to replace ^\R by "leave the field blank", which I tried and then worked...
I'm not sure what \R means, is it a CL/LF combination...?

Quote
It is strange that the ^$ combination does not work; I mean SlickEdit finds newlines through ^$ but does not allow replacement.  ???
$ means end-of-line, but does not include the CR/LF.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6455
  • Hero Points: 503
Re: How can I remove empty lines ?
« Reply #6 on: November 03, 2017, 05:25:08 pm »
\s is [\f\n\r\t\v\x85\p{Z}] -- in the on-line help

\R Match whatever the line ending characters are for that buffer. When used with the pos() function, it matches \n, \r, or \r\n. It's usually better to use \R instead of specifying specific line ending bytes.

$ is a 0 length match. It's true if at the end of the line (sitting on first eol char).