Regex in replacement string for versions

Started by cytochrome, July 23, 2013, 08:01:29 PM

Previous topic - Next topic

cytochrome

Hello,

I have this idiotic problem: my master files are of the type D7K_014812.NEF and some derivatives have TWO underscores like in D7K_014812_ASP_web.jpg

I tried  a number of expressions like (just an example) ^_*[+\-_]* //, nothing does.

How to do it (so the expression works both ways, finds masters from the jpg and vice versa

Francis

Mario

#1
From the top of my head (not tried, please run some tests) and I'm not a regular expressions specialist:


^(_*{name})([+\-_]*[0-9|a-z])*\.(jpg|jpeg|psd|tif|tiff|dng)$


The [+\-_]*[0-9|a-z]* in the default expression allows for things like _ followed by any kind of number of letter. Since your file names can have this multiple times, we just wrap it in ( and ) before adding the *. This allows the entire bulk to repeat, so you can have _abc_012.jpg
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

cytochrome

Thank you, but doesn't work... Your example is close to the default Link expression but I need the Replacement Expression...

For example ^_*// works for D7K_014812.NEF as master and D7K_014812_ASPweb.jpg as version. But as soon as a second underscore or "-"  is present in the name, as in D7K_014812_ASP_web it fails.

I will read a site on regex...

Francis

PS This is to set up the NEF versioning in File relations in Preferences

ChrisMatch

What about this expression:
^(_*{name})[0-9a-z_]*\.(jpg|jpeg|psd|tif|tiff|dng)$



[attachment deleted by admin]

Mario

Ah, sorry. I thought you wanted to detect versions.

Your replacement expression should do what, exactly?

The default:

^_*//

replaces all leading _ with 'nothing'
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

cytochrome

#5
What I want:

I want to set a relation rule to find the versions from the master AND the master from the versions.

- Master : D7K_014812.NEF
- versions: D7K_014812_ASP.jpg,    D7K_014812_ASP_web.jpg,  D7K_014812_ASP_Red_Web.jpg



When I use ^_*// as replacement expression I get 2 Match! for  D7K_014812.NEF and D7K_014812_ASP.jpg but only the master Match for D7K_014812_ASP_web.jpg

For some reason the second underscore is in the way!!

Here the  screen capture

Francis

Thanks Chris, your Link Expression saves my day (well its midnight in France...), I was fiddling with the replacement expression cause I thought the Link expression was "universal". Thanks alot

[attachment deleted by admin]

ChrisMatch

#6
Quote from: cytochrome on July 23, 2013, 11:44:13 PMThanks Chris, your Link Expression saves my day (well its midnight in France...), I was fiddling with the replacement expression cause I thought the Link expression was "universal". Thanks alot
Glad I was able to help.
One additional remark: Mario's expression also worked - in your screenshot where you don't get a match you have no outer braces:
^(_*{name})([+\-_]*[0-9|a-z])*\.(jpg|jpeg|psd|tif|tiff|dng)$

Mario

Yes, the outer braces are the actual trick.

They allow the link expression to find files with any number of appendices, e.g." _web_123_bla". The default expression only allows one of these, which is why your expression does not work with your version file names.

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

cytochrome

I am really confused and all red over the face... I didn't read the Help well enough, normally I do :(

So I tried to play with the Replacement string. it is only after reading Chris' post and looking at his screen capture that I realized my error.

In the string by Chris I had to add \- because in former times I used "-" instead of "_" to include raw developer and size reduction in the name of the jpg versions.

The default Link string in IM5 5.0.104 does not work with my naming scheme, the link is ^(_*{name})[+\-_]*[0-9|a-z]*\.(jpg|jpeg|dng|nef\.dxo|nef\.bib)$ and should be corrected to ^(_*{name})([+\-_]*[0-9|a-z])*\.(jpg|jpeg|psd|tif|tiff|dng)$ as Chris indicated.

I am probably not the only one to use naming like xx_name_LR4_web.

Francis

Mario

I know that the sample string does not work with your file names. But it is only a sample. That's why I provided the solution in my initial reply, the one with the ( and ) in blue.

When using regular expressions the general idea is to have a most exact match, not accidentally pick up the wrong files. This is why my sample expressions are quite tight, allowing only one appendix with a leading _, like "_web" or "_0123abc". If a user uses multiple appendices he can change the regular expression as needed, e.g. by adding the ( and ) as I indicated in my initial reply. For the sample expression, I think I'd better keep the tight expression for now.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

cytochrome

After a detour here, I am back with some more question.

Briefly, my problem is to propagate selected metadata from JPGs to the initial Raw File.

I get it to work using File Relation with this simple setup (attached file). It works basically. I define the two folders to use and the chosen metadata (I choose Rating, keyword and category) get reverse propagated from the jpg to the initial RW2.

Some problems:

- the RAWs are in the form P1234567.rw2, the JPGs are P1234567_ASP.jpg. This works

- I also have JPGs in the form P1234567_B5.jpg. To take care of ASP and B5 I tried different alternatives in the Replacement string : _ASP|B5*//, _(ASP|B5)*//, (_ASP|B5)*//, etc  They all work with P1234567_ASP.jpg and none with P1234567_B5.jpg. Must be simple but beyond my (embryonic) knowledge of regex...

- in the attached capture I declare explicitly the search and destination folders, but it works also with "Where to search": List of folders and "Direction": Up and Down which is more general.

- something else but seems a reported bug: After some write-back the keywords and Artist (that's me!!) are multiplying... I use the french language and there is still a meli-melo of french/english strings in some panels and views. 

I thought this may encourage some others to try doing metadata propagation from within IMatch rather than going the script route (for me more complicated), the File Relation rules are surprisingly powerfull...

Francis

[attachment deleted by admin]