On Mac OS X, you can't use \|
in a basic regular expression, which is what find
uses by default.
re_format man page
[basic] regular expressions differ in several respects. | is an ordinary character and there is no equivalent for its functionality.
The easiest fix in this case is to change \(m\|h\)
to [mh]
, e.g.
find ./ -regex '.*[mh]$'
Or you could add the -E
option to tell find to use extended regular expressions instead.
find -E ./ -regex '.*(m|h)$'
Unfortunately -E
isn't portable.
Also note that if you only want to list files ending in .m
or .h
, you have to escape the dot, e.g.
find ./ -regex '.*\.[mh]$'
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]