Why does this regex not work on linux?
GNU find by default uses emacs regular expressions, you can change that type with -regextype
option (see man find).
If you use -regextype posix-egrep
your expression seems to work. You could then also probably reduce the pattern to ^.+(jpg|gif|exe)$
With emacs: find . -regex '.+\(jpg\|gif\|exe\)$'
. See this section of emacs manual for those specific regex rules. You need to escape |
and ()
for them not to be literal.
In emacs regexps (
, |
and )
are literal unless escaped, this is exactly the opposite of all other regular expression formats.
Your expression works as ^.+\.\(jpg\|exe\|gif\)$
.