Filter results using characters "range"

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
siomosp
Posts: 17
Joined: Sat Feb 27, 2021 11:43 am

Filter results using characters "range"

Post by siomosp »

Hi!
(From a ( quick) search i did not find an answer, so I am posting a new help request)

I want to filter results to specific characters range, for example range 5

My search is "123"

Normal behavior of filter result is
0123
1234
12345
123456
1234567
12345678
123456789
01230
( All the files containing "123")

I want filter to results to
123
1234
12345
01230
( All the files containing 123, and the length is <= 5)

I hope my request is clear
Panagiotis
Mizufluffy
Posts: 62
Joined: Sun Jun 13, 2021 10:22 am

Re: Filter results using characters "range"

Post by Mizufluffy »

I can think of two ways to do this. One is to use len: function, for example len:<=5 (length is less or equal to 5). The other way would be using regex, for example regex:"^.{1,5}$". Character ^ marks the start of a string, period (.) means any character, length is in { and } brackets (from 1 to 5) and character $ marks the end of a string. In other words "match a string that has any character one to five times".

Here's an image of the len: example. On the left you can see all files inside that folder. In the middle results are filtered with "123" and on the right only those with length 5 or less have been kept.
Everything - File name length.png
Everything - File name length.png (137.12 KiB) Viewed 6986 times

Code: Select all

123 len:<=5
123 regex:"^.{1,5}$"
siomosp
Posts: 17
Joined: Sat Feb 27, 2021 11:43 am

Re: Filter results using characters "range"

Post by siomosp »

HI!
Thank you for you suggestions!
Both are working fine with one limitation, the regex is applied at the filename length.
It obvious that i did not clarify my request :(
123 filter
Image
using regex:"^.{1,9}$"
Image
I want to display
Image
123.jpg
01234.jpg
1234.jpg
12345.jpg
and
AS00124567 12345.jpg
raccoon
Posts: 1017
Joined: Thu Oct 18, 2018 1:24 am

Re: Filter results using characters "range"

Post by raccoon »

siomosp wrote: Thu Nov 04, 2021 11:02 am( All the files containing 123, and the length is <= 5)
nopath:len:<=5 123

Turn off Match Path if you don't want parent directories matching "123" to appear in the results.
Mizufluffy
Posts: 62
Joined: Sun Jun 13, 2021 10:22 am

Re: Filter results using characters "range"

Post by Mizufluffy »

siomosp wrote: Thu Nov 04, 2021 8:32 pm 123.jpg
01234.jpg
1234.jpg
12345.jpg
and
AS00124567 12345.jpg
So, the file name must contain substring 123 separated by a word boundary (such as a whitespace character) but that substring may have other characters too, right? If we look at AS00124567 12345.jpg then can you tell does the "12345" part always start with the specified characters? For example in this case "123"? What I mean is that would a file name such as "AS00124567 45123.jpg" also be acceptable?

Because if you all accepted file names have a substring that starts with "123", for example
AS00124567 123.jpg
AS00124567 1234.jpg
AS00124567 12345.jpg
AS00124567 123456.jpg
AS00124567 1234567.jpg
AS00124567 12345678.jpg

Then this should work:

Code: Select all

regex:"\b123\w{0,6}\b"
Note: For length 9 you reduce the number of the characters (123 = three characters, 9 - 3 = 6) from the brackets. This would work for file names as shown above and up to "AS00124567 123456789.jpg". The "\w" part means any letter, digit or underscore. The \b means a word boundary.
Of course, if you only allow numbers after "123" part then you could use

Code: Select all

regex:"\b123\d{0,6}\b" 
instead, the \d means any digit. This would filter out file names such as
AS00124567 123ABCD.jpg

If you allow characters before and after "123" then it's gonna be a little bit more complicated.
Technically speaking you could do regex:"\b\w{0,6}123\w{0,6}\b" but the problem with that is it would allow a substring up to 15 characters with "123" somewhere in the middle.
For example,
AS00124567 456789123456789.jpg
would still be accepted even though "456789123456789" is 15 characters long.

One option in that case would be using regex:\b\w{0,6}123\b|\b123\w{0,6}\b", this accepts either before or after but not both. It has "|" character in the middle that means OR.
For example:
AS00124567 123456.jpg OK
AS00124567 000123.jpg OK
AS00124567 01234.jpg NOT OK

Since you had "01234.jpg" in accepted strings I can only assume that "123" can appear anywhere and characters can be both before and after it as long as the total length that is separated by word boundary stays within limit. Unfortunately I don't have an answer right now. Maybe there is a way but to my understanding it would require knowing the length both before and after. For example, if the substring starts with "123" then there can be up to 6 characters (total of 9) after. However, each character before "123" means there can be one less character after "123". I can't think of a way to do this in regex.

Of course, using OR just like before I could type
regex:"\b123\w{0,6}\b|\b\w{1}123\w{0,5}\b|\b\w{2}123\w{0,4}\b|\b\w{3}123\w{0,3}\b|\b\w{4}123\w{0,2}\b|\b\w{5}123\w{0,1}\b|\b\w{6}123\b"
but I'm sure you could see how this would easily get long and confusing because it separates various possibilities with OR (this OR this OR this OR ...). I'm not even sure if I included every option in that one so I can't recommend using it.
void
Developer
Posts: 16751
Joined: Fri Oct 16, 2009 11:31 pm

Re: Filter results using characters "range"

Post by void »

With Everything 1.5:

I think you will just have to specify each case:
#define:<x=123>regex:\b(#x:|0#x:|0#x:\d|00#x:|#x:\d|#x:\d\d)\b
(x must be a 3 digit number)

The following searches will only match the first 3-5 character word with all digits:

regex:\b(\d{3,5})\b regular-expression-match-1:123
(this will also match 2123)

Try a regex search on the regular-expression-match-1:
regex:\b(\d{3,5})\b regex:regular-expression-match-1:^0*123

If you know where the 3-5 character word with all digits is placed in the filename, regular-expression-match-1: might be helpful for you.


If you are using Everything 1.4, please escape | in your regex terms with double quotes.
For example: regex:"\b\w{0,6}123\b|\b123\w{0,6}\b"
Mizufluffy
Posts: 62
Joined: Sun Jun 13, 2021 10:22 am

Re: Filter results using characters "range"

Post by Mizufluffy »

void wrote: Thu Nov 04, 2021 10:26 pm The following searches will only match the first 3-5 character word with all digits:

regex:\b(\d{3,5})\b regular-expression-match-1:123
(this will also match 2123)

Try a regex search on the regular-expression-match-1:
regex:\b(\d{3,5})\b regex:regular-expression-match-1:^0*123

If you know where the 3-5 character word with all digits is placed in the filename, regular-expression-match-1: might be helpful for you.
This is such a great advice. I regularly use regular expression match columns for finding duplicates or sorting but I didn't even think about first checking the length of string of digits and then using regex match to check if they have substring 123 when I was giving advice earlier. Sometimes it is easy to overlook some solutions and I guess I was complicating the issue in my head.

What void said works great on digits but if a file name such as
AS00124567 A123B.jpg
should be accepted too (it has A123B which is length 5 or below and contains 123) then following regex would accept those kind of cases too:

Code: Select all

regex:\b(\w{3,5})\b regular-expression-match-1:123
Only thing that was changed was \d to \w (digits to word characters). The problem with this is that it would find files such as
AS00124567 12345.jpg
AS00124567 A123B.jpg
but not if the length is increased, for example {3,50}, then it would find files such as this
AS0012456712345.jpg
but not the other two files anymore because it would match only the first part (AS00124567) and couldn't find 123 in there. That's why all digits solution can be more reliable.

The problem above could be solved with something like this:

Code: Select all

regex:\b([^(AS)]\w{3,50})\b regular-expression-match-1:123
This is otherwise the same (with increased length though) but it would not match strings that start with "AS". This way it would match files such as
12345.jpg
AS00124567 12345.jpg
AS00124567 456123.jpg
AS00124567 45612345.jpg
AS00124567 A123B.jpg
(matching happens for the 12345, 456123, 45612345, A123B)
but not
AS0012456712345.jpg
anymore because it starts with "AS" so no match.
(long length version was used only to demonstrate how it would find files compared to the previous example)

Regex is a powerful tool but it needs specific instructions to work so real life examples and knowing what substrings may change and what are staying the same can help with determining the pattern.
siomosp
Posts: 17
Joined: Sat Feb 27, 2021 11:43 am

Re: Filter results using characters "range"

Post by siomosp »

Thank you both for the suggestions!

Code: Select all

regex:\b(\w{1,5})\b regular-expression-match-1:123
is fine!
This regex can be added at search filters?
void
Developer
Posts: 16751
Joined: Fri Oct 16, 2009 11:31 pm

Re: Filter results using characters "range"

Post by void »

To add this search as a filter:
  • In Everything, from the Search menu, click Add to filters....
  • Change the Name to: 123
  • Change the Search to: regex:\b(\w{1,5})\b regular-expression-match-1:123
  • Click OK.
Filters can be activated from the Search menu, Filter bar (View -> Filters), right clicking the status bar, filter macro or filter keyboard shortcut.
siomosp
Posts: 17
Joined: Sat Feb 27, 2021 11:43 am

Re: Filter results using characters "range"

Post by siomosp »

Thank you!
Post Reply