In Visual Studio Code, using the search capability, how can I search for all files that do not contain a certain string? In this case - "OnPush"
Asked
Active
Viewed 4.2k times
40
-
1Probably `^(?![\S\s\r]*OnPush)`, but I can't test now. – Wiktor Stribiżew Jul 11 '18 at 23:07
-
2@WiktorStribiżew when I enable Regex and try that, as well as other possible regex solutions, VS code responds with "Expression Matches Everything" – Craig Smitham Jul 11 '18 at 23:16
-
1May want to check info on the regex flavor first https://stackoverflow.com/questions/42179046/what-flavor-of-regex-does-visual-studio-code-use – Jul 11 '18 at 23:33
2 Answers
38
In general regex, to search for anything that does not contain a certain string, you do stringbefore(?!string)
That is a negative lookahead, it says that only match if whatever you specify as string
is not present. In your case it would be something like [\W\w]+(?!OnPush)
But, Negative Lookaheads aren't supported in VS Code Search... So you can't do much.

Sheshank S.
- 3,053
- 3
- 19
- 39
-
-
2Negative look-ahead isn't supported in VS Code search: https://github.com/Microsoft/vscode/issues/30735 – jabacchetta Jul 12 '18 at 01:23
-
9You need to enable "search.usePCRE2" in VS Code to use negative look-ahead. – Ali Yousuf Mar 15 '19 at 19:54
-
5You don't need to ensable the `PCRE2` setting anymore - in fact it is deprecated. Vscode will use PCRE2 as a fallback automatically now. – Mark Oct 21 '19 at 20:50
-
4VSCode (v 1.50.1) Search works. e.g search for a comma not followed by whitespace `,(?!\s)`. – s3c Nov 03 '20 at 12:55
-
This doesn't work for me in VSCode (v 1.73), I tried to find files in a folder that do not contain the string "$layout" using regex [\W\w]+(?!\$layout), but it still finds files containing "$layout". Am I doing something wrong? – smohadjer Nov 08 '22 at 08:07
8
There is a VS Code extension called Reverse Search It can find files that do not contain a specific string

Danish Sarwar
- 343
- 2
- 8
-
2Is it possible to search only in specific folder and in specific files like .php? – Ivan Topić Jan 13 '20 at 10:19
-
@IvanTopić yes, you can include or exclude files using this extension. – Danish Sarwar Feb 25 '20 at 04:50
-
Reverse Search didn't work for me. I enter "$layout" to find files that don't contain it and in next step I enter "controllers/**" since I only want to find files in controllers folder which don't have $layout in them, but Reverse Search still shows me files containing $layout! – smohadjer Nov 08 '22 at 07:20
-