Named groups and backreferences help

General discussion related to "Everything".
Post Reply
HerbertDBurke
Posts: 3
Joined: Thu Oct 27, 2016 9:19 am

Named groups and backreferences help

Post by HerbertDBurke »

Hi,
With 1.4.1 added perl compatible regex, how to use named groups syntax, any help?
Thanks.
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

Capture and name a group:
(?P<name>...)

Invoke named group:
(?P=name)

For example: find files with the same name part and extension part:
regex:"^(?P<foo>.*)\.(?P=foo)$"

If you use regex: please make sure you escape <, >, | and spaces with double quotes.

https://en.wikipedia.org/wiki/Perl_Comp ... xpressions
HerbertDBurke
Posts: 3
Joined: Thu Oct 27, 2016 9:19 am

Re: Named groups and backreferences help

Post by HerbertDBurke »

Thanks.
:o
Looks like i missed the double quotes, but not just for escape <, >, | and spaces, like

Code: Select all

regex:"(12)\1.txt"
also need double quotes

I did some tests with named groups and backreferences, to match '1212.txt', these syntax all works:
regex:"(12)\1.txt"
regex:"(?<x>12)\k<x>.txt"
regex:"(?'x'12)\k'x'.txt"
regex:"(?'x'12)\k{x}.txt"
regex:"(?'x'12)\g{x}.txt"
regex:"(?P<x>12)\k<x>.txt"

From: http://www.regular-expressions.info/refext.html
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

If you have Allow round bracket grouping enabled from Tools -> Options -> Search you will also need to escape ( and ) with double quotes.
HerbertDBurke
Posts: 3
Joined: Thu Oct 27, 2016 9:19 am

Re: Named groups and backreferences help

Post by HerbertDBurke »

Indeed.

Off the topic, does everything support condition search?
If find a.2.txt also list a.txt,
For example, find mutli groups similar files: a.txt, a.2.txt, c.txt, c.2.txt from list:

Code: Select all

a.txt
a.1.txt
a.2.txt
b.txt
b.1.txt
c.txt
c.2.txt
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

No, not yet, sorry.
maxfactor
Posts: 32
Joined: Tue Nov 08, 2016 4:31 pm

Re: Named groups and backreferences help

Post by maxfactor »

Hi,

is there the possibility to find existing filenames having the same name but different extensions (for example MyMovie.avi and MyMovie.mp4)?

Thanks
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

namepartdupe:

Notes:
Requires Everything 1.4.1
namepartdupe: finds duplicated files and folders with the same name part in the entire index (not the current results).

For example:
namepartdupe:MyMovie
maxfactor
Posts: 32
Joined: Tue Nov 08, 2016 4:31 pm

Re: Named groups and backreferences help

Post by maxfactor »

Wow, thanks, I hadn't noticed it! Works great. Thanks.
maxfactor
Posts: 32
Joined: Tue Nov 08, 2016 4:31 pm

Re: Named groups and backreferences help

Post by maxfactor »

Uhm... I was wrong... I forget to mention that I don't know the file name in advance

#part1
I just want to find what filenames have the same name but a different extension (last .xxx part)
Or at least I know two extensions (mp4 and avi) and I want to get as above.

#part2
Moreover, it seems I can not search for dupe filtering a specific volume only (filename that exists twice only int the same volume).
If i write
dupe: e:
it returns some dupes because the other files (the clones) are in the m: volume... that is a backup drive... and so I'm not interested in that...

Thanks
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

#part1
I just want to find what filenames have the same name but a different extension (last .xxx part)
Or at least I know two extensions (mp4 and avi) and I want to get as above.
that's what namepartdupe: should do.
namepartdupe: will also find duplicated name parts with the same extension, ie the whole file name is duplicated.
#part2
Moreover, it seems I can not search for dupe filtering a specific volume only (filename that exists twice only int the same volume).
If i write
dupe: e:
it returns some dupes because the other files (the clones) are in the m: volume... that is a backup drive... and so I'm not interested in that...
namepartdupe: finds duplicated files and folders with the same name part in the entire index (not the current results).

Please try running a new named instance of Everything and indexing only your m: drive.
maxfactor
Posts: 32
Joined: Tue Nov 08, 2016 4:31 pm

Re: Named groups and backreferences help

Post by maxfactor »

Ok, ok, look at this (I want you know that I studied and put into practice some of your previous teachings)

Search for M: (to get an exhaustive list of all files in volume M:)
Export (to file list)
Open File List (to work only on items contained in M:)
namepartdupe:file:ext:mp4;avi (WOOW! FINALLY!)
Close File List (and go back to ordinary work)

Anyway, I'm very tired of your immediate availability: right today I will make another (small) donation! ;)

Regards
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

Search for M: (to get an exhaustive list of all files in volume M:)
Export (to file list)
Open File List (to work only on items contained in M:)
namepartdupe:file:ext:mp4;avi (WOOW! FINALLY!)
Excellent, I didn't think of doing that.

Thanks for your support.
maxfactor
Posts: 32
Joined: Tue Nov 08, 2016 4:31 pm

Re: Named groups and backreferences help

Post by maxfactor »

Is there a way to invoke a named group (?P=name) to be used as the parameter for the content: function?
void
Developer
Posts: 16683
Joined: Fri Oct 16, 2009 11:31 pm

Re: Named groups and backreferences help

Post by void »

Not yet, sorry.

Added to my TODO list: regvar0:..regvar9: to be substituted with the previous regex search captures, possibly by name too.
maxfactor
Posts: 32
Joined: Tue Nov 08, 2016 4:31 pm

Re: Named groups and backreferences help

Post by maxfactor »

Thanks for TODOing...

These are (some) files I own

Aggiornamento Asset T3.xlsx
Aggiornamento Asset T4.xlsx
Aggiornamento Asset T5.xlsx

and this is a useful-to-me search example:

regex:"(?P<N1>Aggiornamento asset )(?P<N2>T[0-9]+)(?P<N3>.*)"

Based on your assumptions, a search for those containing the N2 result will be (?) like:

regex:"(?P<N1>Aggiornamento asset )(?P<N2>T[0-9]+)(?P<N3>.*)" AND content:regvar3:
Post Reply