Regex alternative patterns

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
Gingko
Posts: 4
Joined: Tue Oct 18, 2016 9:58 am

Regex alternative patterns

Post by Gingko »

Hello,

Normally, using the following regular expression, I should find any file with either the .pdf or the .docx extension:

Code: Select all

regex:^.*\.(pdf|docx)$
… knowing that I use both grouping parenthesis, and the vertical bar for searching among several alternative patterns.

But in Everything (last 1.4.1.932 version, I just upgraded in order to be sure), this doesn't seem to work. Actually nothing is found.

Is Everything using some specific not standard regular expression syntax for doing this?
Or should I have to escape some parts of the expression?
Or should I file a bug report?

Gingko
vanisk
Posts: 152
Joined: Sat Oct 27, 2018 11:33 am

Re: Regex alternative patterns

Post by vanisk »

idk why, but

Code: Select all

regex:^".*\.(pdf|docx)$"
seems to be working.
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: Regex alternative patterns

Post by NotNull »

That's because the pipe symbol ("|") has speacial meaning in Everything: it's used as OR.
That causes your query to be expanded to: regex:^.*\.(pdf OR docx)$.

You can escape the | by enclosing it in "":
regex:"^.*\.(pdf|docx)$"
- or -
regex:^".*\.(pdf|docx)"$
- or -
regex:^.*\.(pdf"|"docx)$
- or -
... etcetera ..

Or, in this specific case, you could also use this as your query:
ext:pdf;docx
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: Regex alternative patterns

Post by NotNull »

vanisk wrote: Mon Feb 11, 2019 3:06 pm idk why, but

Code: Select all

regex:^".*\.(pdf|docx)$"
seems to be working.
Sorry, hadn't noticed your reply when typing mine ...
vanisk
Posts: 152
Joined: Sat Oct 27, 2018 11:33 am

Re: Regex alternative patterns

Post by vanisk »

NotNull wrote: Mon Feb 11, 2019 3:18 pm hadn't noticed your reply when typing mine ...
But, yours is more explanatory. Thanks for explaining why we need to escape |.
Gingko
Posts: 4
Joined: Tue Oct 18, 2016 9:58 am

Re: Regex alternative patterns

Post by Gingko »

NotNull wrote: Mon Feb 11, 2019 3:17 pm That's because the pipe symbol ("|") has speacial meaning in Everything: it's used as OR.
That causes your query to be expanded to: regex:^.*\.(pdf OR docx)$.

You can escape the | by enclosing it in "":
regex:"^.*\.(pdf|docx)$"
- or -
regex:^".*\.(pdf|docx)"$
- or -
regex:^.*\.(pdf"|"docx)$
- or -
... etcetera ..
I see. Thank you very much.

I didn't even notice that I could want to use "|" as a OR operator.

Maybe the need to quote regular expressions could be more underlined.
NotNull wrote: Mon Feb 11, 2019 3:17 pmOr, in this specific case, you could also use this as your query:
ext:pdf;docx
Not really, unfortunately.

I simplified the case for asking the question here, but the regular expression that I want to use is actually much more complex than that.

Gingko
void
Developer
Posts: 15096
Joined: Fri Oct 16, 2009 11:31 pm

Re: Regex alternative patterns

Post by void »

The next major version of Everything will eat the | when used with regex:

For now you will need to escape | with double quotes. Sorry for the inconvenience.
Post Reply