0

Here is my text :

     <---- empty line to delete
     <---- empty line to delete
Lorem ipsum
Lorem ipsum
     <---- empty line to keep
Lorem ipsum
     <---- empty line to delete

Here's what I would like to have using VSCode regex, or any extension you might know about.

Lorem ipsum
Lorem ipsum

Lorem ipsum

Any idea ? Thanks!

EDIT: I might need to precise that I want to achieve this on more than 12000 files. So can't imagine doing this manually.. And I haven't found any extensions yet, neither answers about this subject.

p_duthoit
  • 226
  • 4
  • 19

1 Answers1

2

For empty lines at the end, you can remove them with \n+$(?![\r\n]) in VSCode.

For the first empty lines should work (?) (?<!(.|\n))\n+.

Other flavours of regex have (although they don't seem to work in VSCode) have \A or \` and \Z \' for start and end of file.

s_baldur
  • 29,441
  • 4
  • 36
  • 69
  • Thanks for your help, indeed some lines containing special characters at the end, are selected too. But this puts me on track! Let me check. – p_duthoit May 30 '22 at 10:53
  • 1
    `(?<!(.|\n))\n+` This seems to do the trick, and handles more (all ?) cases. Maybe you can update your answer with it. Thanks didn't know it was possible. – p_duthoit May 30 '22 at 10:58