VS代码正则搜索和替换 - 两个对象的全局搜索之间的空格删除(if和返回)
我想删除此过滤后的搜索之间的界限: 这是我在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
}
I 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!
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
搜索(如果。代码>。请参阅the Regex demo 。
替换
之前在此处输入图像描述“>
更换后
Search by
(if.*?\{)([\s\n]{2,}?)(?=^.*?return)
and replace with$1\n
. See the regex demo.Before Replacement
After Replacement