0

I try to search for all occurences with @author in a project (I am using replace in various files) but I need to exclude a certain author.

My current search string is @author, this shows many results like:

@author John Doe
@author Frank Ermantraut
@author Amasty Team

How can I exclude results with "Amasty Team" in it?

Black
  • 18,150
  • 39
  • 158
  • 271
  • Are you using the "magnifying glass" search and replace in various files, or just the in-document feature? – Wiktor Stribiżew Dec 13 '22 at 13:02
  • I am using the search for various files. – Black Dec 13 '22 at 13:03
  • 1
    Then you can't, since Rust regex does not support lookarounds. Notepad++ has much better regex support for searching in different files. – Wiktor Stribiżew Dec 13 '22 at 13:03
  • Good to know, thank you :) I asked openAI btw and it gave me this regex which does not work `@author\s((?!Amasty Team).)*` – Black Dec 13 '22 at 13:04
  • 2
    Do not ask AI questions like this, it can only provide very basic patterns. Or those that are already known. It cannot tell regex flavors either. – Wiktor Stribiżew Dec 13 '22 at 13:05
  • Yea, it failed on every regex question so far unfortunately. – Black Dec 13 '22 at 13:06
  • openAI almost right: `@author\s(?!Amasty Team)` – rioV8 Dec 13 '22 at 14:58
  • I think `@author\s(?!Amasty Team)\S+` is correct – Black Dec 13 '22 at 15:17
  • Why does your regex work in vscode despite lookarounds not being supported in the Rust regex engine? See https://stackoverflow.com/a/74789031/836330 for an explanation. @WiktorStribiżew – Mark Dec 13 '22 at 17:56
  • I tested it in an online regex tester. In vscode it does not work. – Black Dec 14 '22 at 08:32
  • `@author\s(?!Amasty Team)\S+` works in vscode search across files. – Mark Dec 15 '22 at 02:55
  • It does not work if you search for various files. – Black Dec 15 '22 at 08:56
  • Do you have the Regular Expression button enabled? – Mark Dec 15 '22 at 16:13
  • Not sure why it works now, probably human mistake by me. It works now with that regex I provided here https://stackoverflow.com/questions/74785291/visual-studio-code-ignore-result-if-it-contains-certain-string?noredirect=1#comment131987310_74785291 – Black Dec 16 '22 at 12:04

1 Answers1

0

Here is a demo with search across files working with a regex lookahead.

search with regex lookahead

Mark
  • 143,421
  • 24
  • 428
  • 436