Why isn’t this regex working?
find ./ -regex '.*\(m\|h\)$
I noticed that the following works fine:
find ./ -regex '.*\(m\)$'
But when I add the “or a h at the end of the filename” by adding \|h it doesn’t work. That is, it should pick up all my *.m and *.h files, but I am getting nothing back.
I am on Mac OS X.
On Mac OS X, you can’t use
\|in a basic regular expression, which is whatfinduses by default.re_format man page
The easiest fix in this case is to change
\(m\|h\)to[mh], e.g.Or you could add the
-Eoption to tell find to use extended regular expressions instead.Unfortunately
-Eisn’t portable.Also note that if you only want to list files ending in
.mor.h, you have to escape the dot, e.g.If you find this confusing (me too), there’s a great reference table that shows which features are supported on which systems.
Regex Syntax Summary [Google Cache]