Regular Expression for last characters in file name

Started by musashi77, February 22, 2023, 12:33:24 PM

Previous topic - Next topic

musashi77

Hello,

Im not very good with regular expressions, fortunately the manual has a good example of what I am trying to achieve however It doesnt work for me.

The manual has the following. And I am trying to extract files ending only in "LR" or "LR.jpg"


QuoteFor example, if you include _BW_ as part of the file name to indicate black and white photography, you can combine all these files into a category with the following simple formula:
"@FileRegExp[_BW_]"

When I use the following expression I yield no results at all.
"@FileRegExp[_LR_]"

When I use this expression I get way to many results as I have thousands of pictures ending with "LREX.jpg"
"@FileRegExp[LR]"

I can't seem to only grab the small amount ending on in "LR". The goal is to find them and rename them.

Thanks

sinus

Could you not simply search for .LR in the DB (not regex) and then in the result exclude the LREX (NOT LREX)?

Only an idea, not sure, if it works, but I think, it should.
Best wishes from Switzerland! :-)
Markus

musashi77

Genius.... hadn't thought of excluding what I dont want to see. This worked like like a charm.

"@FileRegExp[LR]" NOT "@FileRegExp[LREX]"

Mario

Your Problem description is unclear.
Do you mean you are looking for file names like "beachLR.jpg" and "beachLR" or what does "ending with LR" mean, precisely? Files with names ending with LR and then followed by an extension? Regular expressions can only work when you know what you are looking for.

(\.LR|\.LR.jpg)$ to find all files with names ending with .LR or LR.jpg
LR$ finds all files ending with LR (no extension)
LR\..*$ finds all files ending with LR, followed by an extension (bananaLR.jpg, beachLR.tif) but not beachLRX.jpg

There are many additional examples and explanations you can directly apply to your problem in the regular expression help: More Examples

Use the RegExp tester app included in IMatch to test regular expressions quickly:

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

Mario

Quote from: musashi77 on February 22, 2023, 01:27:41 PMGenius.... hadn't thought of excluding what I dont want to see. This worked like like a charm.

"@FileRegExp[LR]" NOT "@FileRegExp[LREX]"
This means IMatch has to process all files names in your database twice!
Try my example (see above) first. It needs to check each file name only once.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

musashi77

Great...

Exactly. Looking for anything that ends in LR.jpg so using this expression [LR\..*$] works a treat.

Thanks for pointing out the RegExp tester app, would have saved myself a bunch of time if I had started there instead of 'Google' which just complicated things more haha... good to know its there as I have lots more use-cases where I could utilise some more expressions.