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

jcelle

  • Senior Community Member
  • Posts: 253
  • 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: 253
  • 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: 246
  • 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: 6882
  • Hero Points: 530
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: 424
  • 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: 6882
  • Hero Points: 530
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).