VS代码正则搜索和替换 - 两个对象的全局搜索之间的空格删除(if和返回)

发布于 2025-02-07 06:08:25 字数 1001 浏览 2 评论 0原文

我想删除此过滤后的搜索之间的界限: 这是我在VS代码中搜索中有的正则是 - ^(?![\ t]*//)。*^。*\ bif \ b。*$ \ n \ n \ n(?! 。

t]*// ) 我知道我可以用$ 0保留结果,但不能弄清楚下一部分,任何帮助都将不胜感激!

这是结果中我想要的一个示例:

if o.R == nil {
   
   return nil
}

以下是结果中我不想要的示例:

if err != nil {
        return err
    }

在尝试解决方案后,这是我的VSCODE中的不需要的示例:

if foreign.R == nil {
        foreign.R = &portfolioBinOperationR{}
        return nil
    }

这是我的VSCODE ...我要去哪里?

1 of the 2000 resultsI would like to remove the line in between this filtered search:
Here is the regex that I have in my Search in VS Code - ^(?![ \t]*//).*^.*\bif\b.*$\n\n(?![ \t]*//).*^.*\breturn\b.*$

I would like to get rid of the line in between the if and the return but keep the code, just remove the line in between. I know I can keep the result with the $0 but cant figure out the next part, any help would be much appreciated! Search Box

Here is an example of what I want in the results:

if o.R == nil {
   
   return nil
}

Here are some examples of what I do not want in the results:

if err != nil {
        return err
    }

Also unwanted in the results:

if foreign.R == nil {
        foreign.R = &portfolioBinOperationR{}
        return nil
    }

Here is the my VSCode after trying your solution...where am I going wrong?
After trying solution

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

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

发布评论

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

评论(1

仙女山的月亮 2025-02-14 06:08:25

搜索(如果。代码>。请参阅the Regex demo

替换

之前在此处输入图像描述“>

更换后

”在此处输入图像说明”

Search by (if.*?\{)([\s\n]{2,}?)(?=^.*?return) and replace with $1\n. See the regex demo.

Before Replacement

enter image description here

After Replacement

enter image description here

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