Reputation: 7092
I have the following regex pattern that is working nicely in php
/(^((?!thumb).)*\.jpg)/
My task is to translate this regex in bash, the ideea is to find all the .jpg
files from a directory (recursively) that do not contains the thumb
word in the file path.
I use a structure like this:
find /folder/path -regex '(^((?!thumb).)*\.jpg)'
But i have zero results ? Is there something wrong with my regex in bash?
Upvotes: 1
Views: 572
Reputation: 11216
Think the best you are going to get with find is using two different criteria instead of a single regex
find . -name '*.jpg' ! -regex '.*thumb.*'
Upvotes: 1
Reputation: 29431
You can't use negative lookahead with find
since it's a POSIX regex. You may use this workaround:
find . -iname '*.jpg' | grep -v "thumb"
Which will list all jpg
files then, thanks to grep
exclude all files containing thumb
Upvotes: 1