Find all files whose names do not contain "X" or "Y" strings

Hello.
Is it possible to use a single search string to find all text (.txt) files that do not contain the word "Foo" or the word "Bar" in the file name.
If it's possible with both the "Simple" and the "Advanced" Find panel, then please say how to do both.

I know it can be done with the Advanced tab in the Find panel by adding a couple "And" > "Name" > "No Match" fields, but I'd like to do it with a single "Name" > "Match" field if possible. Also, I'd like to to know if a regular expression could do it.

EXAMPLE:
If a folder contained these files:

Foo xyz.txt
123Bar.txt
Freedom.txt
sky.txt

The search would only match "Freedom.txt" and "sky.txt".

Try an Advanced Filter

Name No Match
Regex: (.*)(foo|bar)(.*)\.txt
Use reg ex: checked

Thanks, but that doesn't return any of the files.
Unless I also include a Name Match *.txt field.
I'd like to do it with a single Name Match, if possible.

A simple wildcard pattern of ~(*(foo|bar)*) will do that.
The equivalent in regex is ^(?!.*(foo|bar)).*$.

1 Like

They both work. Thanks a lot!
You have to uncheck the "Partial Match" box in the Simple pane for that one to work.
To have them match only text files, change them to this:
Simple:
~(*(foo|bar)*).txt
Advanced regex:
^(?!.*(foo|bar)).*txt$

In the regex, you're matching "txt" on the end instead of ".txt". This fixes that:

^(?!.*(foo|bar)).*\.txt$

1 Like