Everything 1.5 Regex (Backreferences)

Discussion related to "Everything" 1.5.
rgbigel
Posts: 53
Joined: Sun Apr 17, 2011 4:00 pm

Everything 1.5 Regex (Backreferences)

Post by rgbigel »

I am looking for items which have double date infos in the file name, but not the same year.
This should work, but doesn't
Code-Snippet

Code: Select all

(_(20(..)) Nr.*\.20(?!\2)(..))
(_(20(..)): Group 2 captures the first 2-digit year suffix.

Nr.*\.20: Matches the separator text between them.

(?!\2): Negative Lookahead. This asserts that the characters immediately following do not match whatever was captured in Group 2. If they do match, the regex engine fails and rejects the match.

(.{2})): Group 3 captures the second suffix, which is guaranteed to be different from Group 2 because of the lookahead check.

Limitations of this approach:

This relies on the engine's ability to evaluate a backreference inside a lookahead ((?!\2)), which is supported in advanced regex flavors like PCRE (PHP/Perl), Python, and .NET

AFAIK this should be the .NET regex in Everything?
brandySnake
Posts: 41
Joined: Fri Sep 24, 2021 3:00 pm

Re: Everything 1.5 Regex (Backreferences)

Post by brandySnake »

At least in my environment, regular expressions that reference a capture group within a negative lookahead construct work correctly (as expected).

As a side note, the regular expression you provided is a bit confusing.
- Includes groups not directly related to this topic
- Contains parts inconsistent with the subsequent explanation (specifically, regex:
(..)
vs. explanation:
(.{2})
).

Personally, I might write it like this:
_20(\d\d) Nr.*\.20(?!\1)\d\d
rgbigel
Posts: 53
Joined: Sun Apr 17, 2011 4:00 pm

Re: Everything 1.5 Regex (Backreferences)

Post by rgbigel »

Thank you for looking, and you are correct that \d\d is better than .. or .{2} (the last two are really the same thing).
But: for me, this does not work.
Try this as a file:

whatever_2026 Nr.001_date_01.02.2014_sumpnels.pdf
__ __
regex:_20(\d\d) Nr.*\.20(?!\1)\d\d shows me nothing at all.

Rolf
brandySnake
Posts: 41
Joined: Fri Sep 24, 2021 3:00 pm

Re: Everything 1.5 Regex (Backreferences)

Post by brandySnake »

If the target pattern string (including regular expressions) contains spaces, it must be enclosed in double quotes to ensure it is recognized correctly.

If you do not enclose it in double quotes, your query will be recognized as two separate parts:
regex:_20(\d\d)
and
Nr.*\.20(?!\1)\d\d


In conclusion, when writing the aforementioned regular expression as an Everything query, it should be written as:
regex:"_20(\d\d) Nr.*\.20(?!\1)\d\d"
rgbigel
Posts: 53
Joined: Sun Apr 17, 2011 4:00 pm

Re: Everything 1.5 Regex (Backreferences)

Post by rgbigel »

Thanks, working .... it was a cut-and-paste problem, i originally had the quotes, but copied straight from my own response, where i left them off. cut-and-waste. :roll: