且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 VSCode 的搜索和替换中匹配不包含字符串的字符串?

更新时间:2023-02-21 15:25:08

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

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.