Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

prescript: I am not sure where this question belongs

i cant say it works on windows but from my understanding this regex is correct and how i would write it (except maybe the ^ at the beginning)



When i run

find -regex '^.+\.((jpg)|(gif)|(exe))$'

my exe does not show up when i write

find -regex '^.+\.exe$'

It does. Why doesnt find -regex want to use () or (()|())? I always thought that was valid for everything.

share|improve this question
up vote 11 down vote accepted

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.

share|improve this answer

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\)$.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.