Incorrect regular expressions work

Found a bug in "Everything"? report it here
Post Reply
redisko
Posts: 1
Joined: Sun Dec 04, 2016 3:53 am

Incorrect regular expressions work

Post by redisko »

Incorrect regular expressions work. For example:

Code: Select all

regex:\.(mp4|avi|mkv|vob|mpg)$
It does not find files with extensions mp4, avi, mkv, vob, mpg. The result completely defies any logic
Generally speaking, this expression should be equivalent to the following:

Code: Select all

regex:\.mp4$|\.avi$|\.mkv$|\.vob$|\.mpg$
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: Incorrect regular expressions work

Post by NotNull »

redisko wrote:Incorrect regular expressions work. For example:

Code: Select all

regex:\.(mp4|avi|mkv|vob|mpg)$
It does not find files with extensions mp4, avi, mkv, vob, mpg. The result completely defies any logic
Generally speaking, this expression should be equivalent to the following:

Code: Select all

regex:\.mp4$|\.avi$|\.mkv$|\.vob$|\.mpg$
The "|" has a double meaning:
It can be an OR in your regex, but it could also mean: the end of the regex and the start of a next query (for example: path:c:\windows)

So, even your second example will probably not give you the right results. This one should give the right results:

Code: Select all

regex:\.mp4$|regex:\.avi$|regex:\.mkv$|regex:\.vob$|regex:\.mpg$

Or escape the | by enclosing it in double quotes (using your second example):

Code: Select all

regex:\.mp4$"|"\.avi$"|"\.mkv$"|"\.vob$"|"\.mpg$
Your short version would become:

Code: Select all

regex:\.(mp4"|"avi"|"mkv"|"vob"|"mpg)$

BTW: I assume this was just an example. Otherwise you could get the same results wit a simple:

Code: Select all

ext:mp4;avi;mkv;vob;mpg
Post Reply