Trying to modify REGEX for versioning that will not allow a "c" or "C" a

Started by Damit, March 12, 2024, 08:45:19 PM

Previous topic - Next topic

Damit

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!

thrinn

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/ 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.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

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. 
Best wishes from Switzerland! :-)
Markus

Damit

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.

Mario

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.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Damit

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:
  • I Added r, R, s & S to the list of rejections as a resized or straightened image an do the same as a crop, but I think with a resized or straightened image we can still keep keywords, which is another case for figuring out if you can have different types  of versions to Masters, one where each transfers a different aspects of the photometadata.
  • I added jpg to the file types acceptable in the first condition as I had ommitted it by mistake.
  • I took out the `.` in ([^cC].*?), as the `.` matched any character except newline characters, so there needed to be at least one character after `(`.
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
  • File Name.ext
  • Ex: Img765.jpg
Descriptive Text
  • Format: {File Name}-{Descriptive Text}.ext
  • Description is placed after the file name because of the way buddy files work.  If you changed the name of the master file then the relation to originals, which are left untouched, is lost. Also, if you added the description prior to the file name, the sorting by title benefits would be lost.
  • MUST BE SHORT. The Descriptive text should be as brief as possible
  • No more than 30 characters
  • Ex: Img765-I Like this Pic.jpg
Alternation (Crop & editing) information
  • Crop or edit info is always placed directly after the descriptive text, if any, and ALWAYS begins with an OPEN PARENTHESIS "(".
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 `_`
  • avoiding confusion with Decreased symbol `-` See below)
d)Cropper's initials capitalized, including initial for middle and/or dual surnames, if used by editor.
  • While a crop is an edit, it is being distinguished in this way to differentiate it from non-cropped edits, of which we can transfer face annotations, regions. Obviously face regions will be misaligned or missing in a cropped photo and this may cause problems
2)   If resized, if not skip to Step 3:
Insert `r` for Resized
  • Resized dimension, if known
  • If listing resizer's initials, insert an UNDERSCORE `_`
  • Insert resizer's capitalized initials, including initial for middle and/or dual surnames, if used by editor
3)If straightened, if not skip to Step 4:
  • Insert `s` for Straightened (Not using `r` to avoid confusion with resized)
  • Rotation angle dimension, if known
  • If listing Straightener's initials, insert an UNDERSCORE `_`
  • Insert straightener's capitalized initials, including initial for middle and/or dual surnames, if used by editor
4)If editing is finalized skip to step 6
5)If edited,
  • Insert "e" for any edit that does not involve cropping, resizing, straightening.
  • Insert edit number, if known, padded with a 0 for single digits
  • Insert editing description within BRACKETS []
  • If listing editor's initials, insert an UNDERSCORE `_`
  • Insert editor's capitalized initials, including initial for middle and/or dual surnames, if used by editor
6)If final edit
  • Insert "fe", designating it as the finalized version of the master, as things stand.
  • Insert edit number, if known, padded with a 0 for single digits
  • Insert editing description within BRACKETS []
  • If listing editor's initials, insert an UNDERSCORE `_`
  • Insert editor's capitalized initials, including initial for middle and/or dual surnames, if used by editor
  • This designation is given to photos that are fully edited and have reached a final state, reaching a satisfactory result for the editor. This does not mean the photo should not be edited again, but that this edit was considered a finished product at one time. There can be other final edits, which will be distinguished by the edit number given.
7)Insert a CLOSED PARENTHESIS `)`
  • Always close alteration information with a closed parenthesis ")"
  • EX: Img0098-Mario Being Silly(c5x7_HFS,e07[x2B&W,+Con]_MJS).jpg
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..

sinus

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?
Best wishes from Switzerland! :-)
Markus

Damit

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))$


sinus

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.  :)
Best wishes from Switzerland! :-)
Markus

Damit

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.

Jingo

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!

Damit

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.

Jingo

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.

Damit

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.

sinus

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.
Best wishes from Switzerland! :-)
Markus

Jingo

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!

Mario

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...
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

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.