用VSCODE删除文件中的空行,但仅在文件的开始和结尾处

发布于 2025-02-02 21:14:42 字数 445 浏览 1 评论 0原文

这是我的文字:

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

这是我想使用vscode REGEX或您可能知道的任何扩展名。

Lorem ipsum
Lorem ipsum

Lorem ipsum

有什么想法吗?谢谢!

编辑:我可能需要确切地说,我想在12000多个文件上实现此目标。因此,无法想象手动做这个。而且我还没有找到任何扩展名,也没有关于这个主题的答案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情哥ㄟ 2025-02-09 21:14:42

对于末尾的空行,您可以使用\ n+$(?![\ r \ n])在VSCODE中删除它们。

对于第一条空行应该工作(?)(?&lt;!(。| \ n))\ n+

Regex的其他口味具有(尽管它们似乎在VSCODE中不起作用)具有\ A\\ z \'用于文件的开始和结尾。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文