Page 1 of 1

Regex alternative patterns

Posted: Mon Feb 11, 2019 2:53 pm
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

Re: Regex alternative patterns

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

Code: Select all

regex:^".*\.(pdf|docx)$"
seems to be working.

Re: Regex alternative patterns

Posted: Mon Feb 11, 2019 3:17 pm
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

Re: Regex alternative patterns

Posted: Mon Feb 11, 2019 3:18 pm
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 ...

Re: Regex alternative patterns

Posted: Mon Feb 11, 2019 3:23 pm
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 |.

Re: Regex alternative patterns

Posted: Tue Feb 12, 2019 8:32 am
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 pm
Or, 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

Re: Regex alternative patterns

Posted: Wed Feb 13, 2019 7:28 am
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.