It was a very open thread. I bring a solution to my own problem on the table and hopefully clarify something for you and other users looking for reliability (like me).
In my case, my mac had a bunch of duplicate photos. When macs make duplicates, they add a space and a number to the end before expansion.
IMG_0001.JPG can have complex complexity with IMG_0001 2.JPG , IMG_0001 3.JPG and so on. In my case, this went on and amounted to about 2,600 useless files.
To push things, I went to the folder in question.
cd ~/Pictures/
Next, we show ourselves that we can list all the files in a directory. You will notice that in regex you must include . which says "look in this directory". In addition, you must match the entire file name, therefore .+ Must catch all other characters.
find -E . -regex '\..+'
Accordingly, the results will lead to strings that you will need to match, including the one mentioned earlier . i, slash / and everything else.
./IMG_1788.JPG ./IMG_1789.JPG ./IMG_1790.JPG ./IMG_1791.JPG
Therefore, I cannot write this to find duplicates, because it does not include "./"
find -E . -regex 'IMG_[0-9]{4} .+'
but I can write this to find duplicates, because it includes "./"
find -E . -regex '\./IMG_[0-9]{4} .+`
or a more fancy version of .*/ , as mentioned by @ jackjr300, does the same.
find -E . -regex '.*/IMG_[0-9]{4} .+`
Finally, this is the confusing part. \d not recognized in BSD. [0-9] works just as well. Other users' answers provide a guide to re_format , which lists ways to write common patterns that replace things like \d funny square-colon syntax that looks like this: [:digit:] . I tried and tried, but it never works. Just use [0-9] . In my case, I spent a lot of time thinking that I should use [:space:] instead of space, but I found (as usual!) That I just needed to breathe and really read the regular expression. This turned out to be my mistake. :)
Hope this helps someone!