Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

from http://www.velocityreviews.com/forums/showpost.php?p=382944&postcount=3

^.+\.((jpg)|(gif)|(exe))$

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

2 Answers 2

up vote 10 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

 
discard

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.