I am working on a regex expression for another medium and thought I could get some help here. I dont know if this is the proper place, but if the subject needs to get moved I apologize in advace.
I wrote this regex to match .cr2 files. For a match the compared file must have the same file name {name} and then requires a "(" for .cr2 files, but not jpg, .jpeg, .dng, .tif, or .tiff files. Here is the expression: ^({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!
As I do not see a direct context with MP3tag I think this topic is off-topic.
If it is related closer to MP3tag than it appears at the moment, further details would be needed like real source data, examples of expected target strings.
Generally, for testing regular expressions, @lyricslover was so kind to supply this link:
I completely get it. I just thought I would ask. I Have gotten the script to work except it will not work if there is nothing after the (. For example, test(.jpg does not match, and I have not been able to figure out why.
Here it is as is: ^({name})(\(([^cC|rR|sS].*?)\.((jpg|jpeg|cr2|dng|png|tiff|tif))?|\.(jpg|jpeg|dng|png|tiff|tif))$
^: Asserts the start of the line.
({name}): Matches the filename prefix specified by {name}.
\(: Matches an opening parenthesis (.
([^cC|rR|sS].*?): Matches any character except c, C, r, R, s, or S immediately following the opening parenthesis, followed by any number of characters (non-greedy).
[^cC|rR|sS]: Matches any character except c, C, r, R, s, or S.
.*?: Matches any number of characters (non-greedy).
\.: Matches a dot ..
((jpg|jpeg|cr2|dng|png|tiff|tif))?: Matches one of the specified image extensions (jpg, jpeg, cr2, dng, png, tiff, tif) optionally. The whole extension part is enclosed in a capturing group and made optional.
|: Alternation to match filenames without parentheses.
\.: Matches a dot ..
(jpg|jpeg|dng|png|tiff|tif): Matches one of the specified image extensions.
Thank you for trying to help Florian! Unfortunately, while that does the trick for the case with nothing between the ( and the . if I have more than one character after the `(' there is not match. I need expression that will allow any character or space, except c,r,s or their capitalizations as the first character. After that first character all characters are fair game. The one I wrote above does that except for the case with nothing after the parenthesis, which, really, whould never happen, but just in case I am trying to tackle that condition.
Maybe if I explain what I am trying to do. I have a master photo file that is a .cr2, lets just say it is IMG444.cr2. I want to group versions, or edits/copies of this file with this file through a link. The link is defined by a regular expresion (the one above). I am defining a condition where if the version of the .cr2 file 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.
Again, no biggie if people can't help. The script as is works pretty well, it just bothers me that there is that one condition where it will not. Since some here are versed in RegEx I thought I would ask off-topic.