photools.com Community

IMatch Discussion Boards => IMatch Scripting and Apps => Topic started by: Damit on March 12, 2024, 08:45:19 PM

Title: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 12, 2024, 08:45:19 PM
I wrote this regex to match .cr2 for versioning requiring "(" for .cr2 files, but not jpg, .jpeg, .dng, .tif, or .tiff files
^({name})((\([+|,|'|!|;|\-|_|\(|\)|\{|\}|\[|\]|0-9|a-z ]*\.(cr2))|(\([+|,|'|!|;|\-|_|\(|\)|\{|\}|\[|\]|0-9|a-z ]*\.(jpg|jpeg|dng|png|tiff|tif))|\.(jpg|jpeg|dng|png|tiff|tif))$

I want to modify it so there cannot be a "c" or a "C" as the first character after the parenthesis, but any character after.  The code should look very much like the one above with the addition of [^cC] somewhere but everywhere I try I get an invalid argument.  The closest I got was
^({name})((\([^cC][+|,|'|!;_\(\)\{\}\[\]0-9a-z ]*\.(cr2))|(\([^cC][+|,|'|!;_\(\)\{\}\[\]0-9a-z ]*\.(jpg|jpeg|dng|png|tiff|tif))|\.(jpg|jpeg|dng|png|tiff|tif)))$

but that is invalid and ChatGPT is not helping (Stupid bot!). Any help would be greatly appreciated!
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: thrinn on March 13, 2024, 08:00:15 AM
This regex looks awfully complex. I am no expert for regex, but I use them occasionally.

Could you please post some examples how your file names actually look like? Preferably for a file that should be matched, but also for a file that should not be matched. It looks to me as if you are using a lot of special characters (like brackets, comma, semicolon, even exclamation mark) as part of your file names?

I tried your first regex at https://regex101.com/ (https://regex101.com/) with a pseudo file name of
IMG_123(some test).cr2
My guess was that this name should be matched, but it did not. So I suppose I misinterpreted your regex.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: sinus on March 13, 2024, 08:49:57 AM
Like Thorsten, I am not a regex expert, I know regex on the lowest level. 
But this regex looks really very complicated for me. 
Hence I can not help for sure, sorry.

I hope, you can find a good solution. 
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 13, 2024, 09:55:46 PM
Thank you. I am working on a solution: This is what I have so far:
^({name})(\(([^cC].*?)\.((jpeg|cr2|dng|png|tiff|tif))$|\.(jpg|jpeg|dng|png|tiff|tif))$
As you said, the other one was overly complicated. This one works for files with the same name and a different extension, or of the same name followed by an open parenthesis, with the first letter not being a c for any number of files.
I am working on a file naming system, and I am using C for Cropped. I do this so that I will not propagate face regions of cropped edits. For now, I am just working on the system but will consult with Mario before doing so in case there are some caveats I should consider. The Exclude from Hierarchical Keywords option taught me to ask first just in case there is some danger that is not documented.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Mario on March 14, 2024, 09:21:15 AM
QuoteI do this so that I will not propagate face regions of cropped edits.
Just in case: propagating face regions between files with different dimensions is not a good idea. The face regions may end up at the wrong position in the other file.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 14, 2024, 06:18:34 PM
Quote from: Mario on March 14, 2024, 09:21:15 AM
QuoteI do this so that I will not propagate face regions of cropped edits.
Just in case: propagating face regions between files with different dimensions is not a good idea. The face regions may end up at the wrong position in the other file.
Yep, I deal with this in the rules I set up, but I appreciate the reminder!
Here is the script as it stands with further tweaking, in case it may be helpful:
Rules:.Cr2 requiring `(` for .cr2 files, but not jpg, .jpeg, .dng, .tif, or .tiff files, rejecting matches when there is a `c` `C` `s` or `S` after the parenthesis (refer to file naming scheme doc).
In the script below, I am defining a condition where if the version of the .cr2 is a .jpg, .jpeg, .png, .dng, .tif or .tiff, it must have either the same exact name OR a `(` after the master file name. If I did not require the `(` img77 will be related to img7765 or img777 or anything with any character after "img77." Also, note that if a version of a .cr2 is a .cr2 file, it must have a `(` after the master file name, as it is not included in the second condition. If either of these conditions are not met, there will be no match.

Script: ^({name})(\(([^cC|rR|sS]*?)\.((jpg|jpeg|cr2|dng|png|tiff|tif))?|\.(jpg|jpeg|dng|png|tiff|tif))$

Changes to the Previous Script:
Further Explanation:
In regular expressions, the dot (.) matches any character except newline characters. So when you include the dot before *?, it requires at least one character to be present after the opening parenthesis in order for the match to occur.
By removing the dot (.), the expression ([^cC|rR].*?) matches any sequence of characters (including none) as long as the first character is not 'c' 'C' 'r' or 'R'.  This change allows filenames with nothing after the parenthesis to match properly. While I would never alter the title in this fashion, I still want to match this condition.

Here is the file naming scheme as I have developed it to this point, that pairs with this versioning concept"
Basic
Descriptive Text
Alternation (Crop & editing) information
Order of listing
1)If cropped, if not skip to Step 2:
a)Insert "c" for Crop
b)Insert aspect ratio, if known
c)If listing cropper's initials, insert an UNDERSCORE `_`
d)Cropper's initials capitalized, including initial for middle and/or dual surnames, if used by editor.
2)   If resized, if not skip to Step 3:
Insert `r` for Resized
3)If straightened, if not skip to Step 4:
4)If editing is finalized skip to step 6
5)If edited,
6)If final edit
7)Insert a CLOSED PARENTHESIS `)`
Editing Abbreviation Key
•   - = Decreased
•   + = Increased
•   B&W = Black and White
•   Br = Brightness
•   C = Crop
•   Contr: = Contrast
•   Crv = Curves
•   BrtExp = Exposure
•   Filt =  Filter
•   Highl = Highlights
•   Midt = Midtones
•   Sat = Saturation
•   Shad = Shadows
•   Sharp = Sharpness.
•   Temp = Temperature
•   Tint = Tint
•   Vign = Vinette
•   NR = Noise Reduction
•   Hue = Hue
•   WB = White Balanced
•   Lvl = Levels
•   Grad = Gradient
•   G-Blur = Gaussian Blur
•   LensC = Lense Correction
•   SelC = Selective Color
•   Sep = Sepia
•   CA = Chromatic Abberation
•   SpotH = Spot Healing
•   Fill = Fill
•   CG = Color Grading
•   x2 = Converted to
•   Fmt = Format
•   ARatio = Aspect ratio
•   R = Resized
•   Res = Resolution
•   WMark = Watermark
•   S = Straightened/Rotated
•   Desat = Desaturated
•   CCast = Color Cast

Any questions, comments and/or criticisms are welcomed..
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: sinus on March 14, 2024, 06:54:56 PM
You mean, this is a normal filename in you system?

Img0098-Mario Being Silly(c5x7_HFS,e07[x2B&W,+Con]_MJS).jpg

If so, if it works for you, why not.
I personally would never use such long abbreviaton, though my filenaming-system is also not the shortest.

And specialy, do you not have the date and maybe the time in your filename?
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 14, 2024, 07:09:11 PM
I am currently trying to settle on a new file naming scheme.  I know it is long, but I do not know where to put editing information. I am a newbie at this, so I am trying to figure out what is best. 

This is a working idea that I am sure will involve, but since it takes careful consideration, I thought I would get ahead of the game. I am not employing it and am just experimenting with the versioning, not transfering anything at this point, just testing and seeing what happens.
As far as date, that is included in the folder name of which these files are contained. My folders are formatted YYYY-MM-DD-Short Description. The time is stored in the files under DateSubjectCreated.

Also, I realized there was an error in my script, and it will not accept c, s, or r anytime after the '(' so I had to add back the `.` and just deal with the fact that having nothing after the `(` will not match.  If anyone can figure out why this is and how to correct the script, please let me know.  For now, I will just have to stay with:

^({name})(\(([^cC|rR|sS].*?)\.((jpg|jpeg|cr2|dng|png|tiff|tif))?|\.(jpg|jpeg|dng|png|tiff|tif))$

Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: sinus on March 14, 2024, 07:43:41 PM
Having date, maybe time, in the filename is important for me. 
I can backup files, send files, copy, shuffle around and so on, and I know always the date. 

This is also true outside of IMatch, I kow always, what date the file has.

And not least, it is important for sorting. 

I personally would never ever do a filename-system without having the date in the file, and for sorting, like you YYYY at first, followed by month and day. 

But we know, users has a lot of workflows and file/foldernaming-systems. 
What is important for one, is not for the next.

I am sure, you will find a good system for you.  :)
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 14, 2024, 08:21:17 PM
Thank you for your contributions and suggestions.  I will consider adding the date. You have been doing this for a long time, from what I have read, and I am sure you have good reasoning behind you need for a date. Let's see if others have suggestions. I just included my naming scheme as thrinn had some questions on how I would name my files.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Jingo on March 15, 2024, 12:45:23 PM
Like Markus and others... I totally keep the filename simple: Camera Model-Month-Day-Id# from camera.jpg  ie: OM-1_03-06-P3061549.

This filename is for a fully processed RAW that is indexed in IMatch.  ALL other info goes into the image metadata which is then exported back into the file when ready.  My RAW files have the exact same naming structure so if I ever want to edit an item again, I simply go to that folder, find the year/month and file name and edit away in DxO PL7 (or whatever editor du jour I'm using).

I've never had the need to know what I did to edit a RAW file in my finished JPG and if I ever wanted to see what edits I made I'll just pull the original RAW file up in my editor.

Everyone has a different workflow though and different wants/needs so if it works for you, then that is great!
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 15, 2024, 04:37:42 PM
Thank you Jingo, I appreciate your input. I do see a KISS trend. I am weighing it. Maybe things are different for me, as I am doing this more as an amateur, cataloguing my personal images, but also all the artistic photography that I may but up somewhere, so I am trying to cover those bases. 

I do think there probably is a better place for editing information, and if I took the actual edits out, the name would only have6-8 characters added at most for version and edit info. I and my wife mostly edit in Photoshop, so maybe just use the History log.  Then I will only have to add the c,s or r, the aspect ratio (which I think is helpful) the e or fe for edit or final edit, the number of the edit and the initials. As most it would add c10X12_HFS,fe05_MJS.  That is 19 characters, but if I keep them at the end of the filename, it will not be so obstructive.

As far as the descriptive text, maybe I will use XMP fields for title and description, but something inside of me wants to keep at least a modicum of the description in the file name.  Maybe old habits, and bad ones at that, but if I am not using something like IMatch to browse and stuck with windows explorer, it would make things easier to spot.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Jingo on March 15, 2024, 10:13:13 PM
Quote from: Damit on March 15, 2024, 04:37:42 PMMaybe old habits, and bad ones at that, but if I am not using something like IMatch to browse and stuck with windows explorer, it would make things easier to spot.

I too often search/view images outside of IMatch and only having a date and camera body in the filename can be tricky - however, I also use other tools to find images when I don't fire up IMatch. 

To search image metadata outside of IMatch, I use Everything which enables me to search XMP metadata for a quick find of Images.  I also rely upon XYPlorer's "Mouse Down Blow Up" to quickly hold down over a filename to see a preview of the image.. it helps when you need to narrow things down a bit if you are just running through images in a folder.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Damit on March 15, 2024, 10:54:03 PM
Cool! I bought XYPlorer based on advice I read on this thread, perhaps from you, so I will consider that when thinking about the form of my file naming scheme.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: sinus on March 16, 2024, 08:10:55 AM
Damit, you have somewhere above written about description.
I think, not a lot of people do add a  desc into the filename.
I do. And over the years, I am very happy, that I did this. It is astonishing, what we (usually) can remember. I have over 360'000 image, and I can remember a lot simply by the short description in the filename.

This helps me not only with IMatch, also outside of IMatch, then with backups, or if I sort some images or whatever. Of course, like you do now, I think, I have also in the past tried this and that.

The most important things, nowadays, I would say is consistency.
Like Jingo mentioned somewhere, if I want change something in my filesystem, (and in the past I did), then this is very very helpful.

And if I look at my filenaming, for me the most important things are
Date and time at the beginning
a short description

Just in case, if you are interested, here are some filenames from my DB:

19681005-1928-463781-c-art-high-noon_o.jpg
19860426-1735-359634-c-kat-tschernobyl_a.jpg
20020111-1016-018463-s-sin-hessi_o.jpg
20120828-1604-183889-s-gou-oswald-catering_m_v1.jpg
20160112-1007-277369-s-ref-mueller-katy_m.nef
20201120-1826-398597-s-coo-geschenkkorb_m.nef
20201120-1826-398597-s-kun-geschenkkorb_m_v1_f.jpg
20240216-1437-467778-s-coo-kaffee-bertschi_m_v1.jpg

I am curious to see, with what system finally you will end (or start).
In any case, good luck.
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Jingo on March 16, 2024, 01:05:49 PM
Quote from: Damit on March 15, 2024, 10:54:03 PMCool! I bought XYPlorer based on advice I read on this thread, perhaps from you, so I will consider that when thinking about the form of my file naming scheme.
No problem.. I'm a huge XYPlorer fan!  Also, Everything is free so easy to check out... note: only the new beta version has the XMP fields available.. it is a bit of a convoluted process to search XMP at the moment... but since it is still in beta, I'm sure it will eventually be simpler.  Enjoy!
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Mario on March 16, 2024, 01:11:48 PM
Quote from: Jingo on March 15, 2024, 10:13:13 PMrely upon XYPlorer's "Mouse Down Blow Up" to quickly hold down over a filename to see a preview of the image.. it helps when you need to narrow things down a bit if you are just running through images in a folder.
Does this work well with RAW files?

LibRaw or WIC sometimes take several seconds to produce a preview of suitable size or to develop the RAW when the embedded preview is very tiny.

If you have the Quick View Panel open (docked or on a separate monitor), IMatch does the same. Loading the file last clicked or navigated to via cursor keys asap.

If the file is a RAW file, there might be a pause if there is no cache image yet and a longer pause (3-10 seconds) if the embedded preview cannot be used due to cache minimum dimensions not being met and the full RAW has to be developed. The time depends on the RAW format and variant. Some NEF files in my library take WIC 10 seconds to develop...
Title: Re: Trying to modify REGEX for versioning that will not allow a "c" or "C" a
Post by: Jingo on March 18, 2024, 12:18:02 AM
Yes.. I have no delay in performing a MDBU over a RAW file such as NEF's... they show within a millisecond and it is quite handy for a quick preview.