Issue
I wanted to find all files with the extension .png and .jpg in a directory, but as soon as I try to search for two extension with the group matcher from regular expression it doesn't find anything.
Does the command "find" not support groups, or am I using them wrong. I used https://regex101.com/ to test the expression below and it gave me the result I expected.
I tried the command find ./assets -regex '.*\.(png|jpg)'
but this doesn't show any files.
If I use
find ./assets -regex '.*\.png'
find ./assets -regex '.*\.jpg'
it finds all files I search for, but I need it in one command.
I also, just for test purpose, tried find ./assets -regex '.*\.(.*)'
which also finds not a single file. And adding -regextype posix-extended
gives an error.
It should match for example:
./assets/image.png
./assets/subdir/image2.png
./assets/image3.jpg
There are some JSON files as well which should not be matched, like:
./assets/image.json
./assets/subdir/image2.json
Don't know if this is relevant or not but I'm on a MacBook and use the zsh terminal.
Solution
As the first comment says I missed the -E option to use extended (modern) regex.
find -E ./assets -regex '.*\.(png|jpg)'
Answered By - Alexander Pissinger Answer Checked By - David Goodson (WPSolving Volunteer)