Linux – Why does this regex not work on linux

findlinuxregex

I can't 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.

Best Answer

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.

Related Topic