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.

link|improve this question

50% accept rate
feedback

2 Answers

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

link|improve this answer
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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