如何在 VSCode 的搜索和替换中匹配不包含字符串的字符串? [英] How do I match strings not containing strings in VSCode's search and replace?

查看:108
本文介绍了如何在 VSCode 的搜索和替换中匹配不包含字符串的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 VSCode 的搜索和替换中匹配不包含字符串的字符串?
我在谷歌上搜索到的所有内容(甚至在这里)都是如何通过编程来完成的,
如何匹配不包含单个字符的字符串,
或与 VSCode 的正则表达式处理不兼容.
这个问题没有'回答我的问题.
这个问题是专门通过编程提出的.
我上次提问时已经说过的相关/适用,以及为什么该方法不相关/不适用.
我不应该用这个编辑重新发布,因为原版已经说明了为什么这个问题没有帮助.
但我需要这样做来匹配不包含字符串的字符串,而不是其中的单个字符.
我还需要使用正则表达式将所述字符串输入到其自匹配中.

我的应用程序.
我需要匹配除此匹配的字符串之外的所有内容.
recipes.add(Shaped|Shapeless)\((.+), \[(((<(.+)>|null)|(<(.+)>|null), (<;(.+)>|null)|(<(.+)>|null), (<(.+)>|null), (<(.+)>|null)|(<(.+)>|null), (<(.+)>|null), (<(.+)>|null), (<(.+)>|null))\]\);

解决方案

你的问题有点过于宽泛,没有具体的例子,但基本上你可以做的事情来避免子字符串是:

START(?:(?!WHATIWANTTOAVOID).)*END

或获得最短匹配:

START(?:(?!WHATIWANTTOAVOID).)*?END

这个想法是,对于 START 和 END 之间的每个位置,WHATIWANTTOAVOID 使用负前瞻(后面没有)进行测试.

前瞻是不使用字符的零宽度断言,因此在示例中,前瞻和 .(点)在主题字符串中的相同位置进行测试.

How do I match strings not containing strings in VSCode's search and replace?
Everything I've found googling (even on here) is either how to do it in via programming,
how to match strings not containing individual characters,
or not compatible with VSCode's regex processing.
This question doesn't answer my question.
That question is specifically via programming.
Which I already stated last time I asked was not relevant/applicable, and why that method isn't relevant/applicable.
I shouldn't have to repost with this edit, as the original already stated why that question doesn't help.
But I need to do it to match strings not containing the string, and not the individual characters in it.
I also need said string to in and of its self match using regex.

My appoligies.
I need to match everything but the strings matched by this.
recipes.add(Shaped|Shapeless)\((.+), \[((<(.+)>|null)|(<(.+)>|null), (<(.+)>|null)|(<(.+)>|null), (<(.+)>|null), (<(.+)>|null)|(<(.+)>|null), (<(.+)>|null), (<(.+)>|null), (<(.+)>|null))\]\);

解决方案

Your question is a bit too broad and without a concrete example, but basically a thing you can do to avoid a substring is:

START(?:(?!WHATIWANTTOAVOID).)*END

or to get the shortest match:

START(?:(?!WHATIWANTTOAVOID).)*?END

The idea is that for each position between START and END, WHATIWANTTOAVOID is tested using a negative lookahead (not followed by).

A lookahead is a zero-width assertion that doesn't consume characters, so in the example the lookahead and . (the dot) are tested at the same positions in the subject string.

这篇关于如何在 VSCode 的搜索和替换中匹配不包含字符串的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆