40

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"

Craig Smitham
  • 3,395
  • 4
  • 31
  • 38
  • 1
    Probably `^(?![\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
  • 1
    May 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 Answers2

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
  • Try now. I'm downloading VS code right now will test there – Sheshank S. Jul 11 '18 at 23:40
  • 2
    Negative look-ahead isn't supported in VS Code search: https://github.com/Microsoft/vscode/issues/30735 – jabacchetta Jul 12 '18 at 01:23
  • 9
    You need to enable "search.usePCRE2" in VS Code to use negative look-ahead. – Ali Yousuf Mar 15 '19 at 19:54
  • 5
    You 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
  • 4
    VSCode (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
  • 2
    Is 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
  • As of early 2023, Reverse Search v2.0.2 worked very well for me. – Karl Jan 13 '23 at 02:47