Filter by filename with 3 digits at the end

Started by frankdarwin, April 29, 2022, 11:04:11 PM

Previous topic - Next topic

frankdarwin

I want to search for all files in the database whose filename ends with a 3 digit number.

Can anyone give me a tip on how to do this?

JohnZeman

One way you could do it is to use the File Window search bar.

Configure the file window search bar as shown in my screenshot (enable regular expressions and enable the search the entire database option).

In my attached screenshot I'm searching my entire database for all DNG, TIF, and JPG files whose filename ends in the number 310

310\.(dng|tif|jpg)

Or instead of searching for a specific 3 digit number if you just want to return all file names that end in any 3 digit number you could use this in the file window search bar instead.

[0-9][0-9][0-9]\.(dng|tif|jpg)

Again I'm filtering all DNG, TIF, and JPG files in my example, you would need to use the file extensions you have in your database.

Mario

Very good.

You could shorten this a bit by using [0-9]{3} which means "3 digits".

For the OP: IMatch uses Perl regular expressions and you'll find ton of examples on the Internet.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Tveloso

...and if your requirement is to match FileNames ending in three digits, which are not preceded by other digits (perhaps names of that form are significant in your workflow), you could refine the Regular Expression even further to isolate only those.

For example, the sample Regular Expression that John gave (and Mario refined):

    [0-9]{3}\.(dng|tif|jpg)

...will match all of these FileNames:

    IMG_1234.JPG <=(match)
    20220430_075759.JPG <=(match)
    SomeString_123.JPG <=(match)

...but if your intention is to find only the last file, you could do something like this:

    [^0-9][0-9]{3}\.(dng|tif|jpg)

Now only the last file will match:

    IMG_1234.JPG <=(no match)
    20220430_075759.JPG <=(no match)
    SomeString_123.JPG <=(match)

And if, given these two files (which both match the current expression):

    ABCD_123.JPG <=(match)
    ABCD123.JPG <=(match)

...you actually only want to match the first one (because your naming convention always uses an underscore before the three digits, and that's what makes their names significant), you can include the literal underscore instead:

    _[0-9]{3}\.(dng|tif|jpg)

Now only one of the two files will match:

    ABCD_123.JPG <=(match)
    ABCD123.JPG <=(no match)

And if you have other extensions, and don't want to list them all, you could do something like this:

    [^0-9][0-9]{3}\..{3,4}$

...which will match:

    ABCD_123.DNG <=(match)
    ABCD123.TIF <=(match)
    ABCD_456.TIFF <=(match)
    ABCD_456.JPG <=(match)
    ABCD_456.JPEG <=(match)

...but not:

    ABCD_456.OTHER <=(no match)

Regular Expressions are very powerful!
--Tony

Mario

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

frankdarwin

Quote from: Mario on April 30, 2022, 03:11:24 PM
Very nice. Thank you.
Exactly what I was looking for. Thanks to all for the different suggestions!