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.

4
  • How do you define empty line? Only allowed characters are spaces? Commented May 30, 2022 at 10:30
  • No. empty empty. No spaces. Commented May 30, 2022 at 10:33
  • Check this : stackoverflow.com/questions/30884131/… Commented May 30, 2022 at 10:42
  • @kipy thank you but this is only white spaces, no new lines. Commented May 30, 2022 at 10:51

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
(?<!(.|\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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.