Rename using regular expressions - one expression to deal with 2 different filename situations

I hope someone can help me - I'm struggling.

I'm using a custom saved rename preset for handling a standard filename rename I must do on a daily basis, many times a day.

Sample filenames I face are:

test - dkc - invoice - maint misc - test.pdf
test - vet - invoice - maint misc - test.pdf
transaction_something.pdf

In any of these cases, I need the rename present to produce this:
2024-05-07 - dateitem - dkc - invoice - maint misc - test.pdf

The precise date is already written into the rename preset, as is " - dateitem - ". The idea is that the first part of the existing name is removed and replaced with the date and the " - dateitem - " addendum, then followed by the rest of the existing/current name. BUT, also, the first segment of the existing filename is removed, to get the result I need.

My preset works perfectly for files which have either of these standard formats:
test - dkc - invoice - maint misc - test.pdf
test - vet - invoice - maint misc - test.pdf

...but it does not work if the filename has this format:
transaction_something.pdf

I can of course create a different preset for each of the two scenarios, but I'm hoping to have a single preset which can handle both situations.

I've included screenshots of how my customer preset is currently working, here:

and here:

and here, where I currently have to manually adjust my rename preset:

I hope I've explained this well enough... and I really hope someone can help with providing a single rename preset that can correctly rename these files in either format.

Thanks.

If I understood correctly, you want to remove "transaction_" from the last file, right?
This should work:

temp

In case you don't know it yet, my go-to regex testing page is https://regex101.com/. I use it all the time... :smiley:

Try (-*)(.*) instead of -(.*)

regex quantifier * will match zero or more of preceding token, + will match one or more

don't forget to change the capture group to 2

No, not quite right. When the filename is "rransaction_something" I was to preserve the entire exiting name but add the " - dateitem - " to th e front of the file name, keeping "transaction_something" in the name but following the inserted new bit.

I can't copy/paste the expression you're suggesting (could you add it as a non-pic?) but based on your question, I don't thikn that will solve the problem anyway.

Thank you, though. :slight_smile:

I tried this - didn't work. not the result I wanted.

Looks valuable, thanks, but I'm going to have to spend a lot time figuring out how to make use of it. So my hope is that very clever person reading this thred will be able to give me the "easy" solution that I am stupidly not seeing. :slight_smile:

Using a rename script is probably easier than coming up with a single regex (especially if more filename formats are needed in the future).

You could adapt this one: Script to perform multiple Regular Expressions

Alternatively, for a toolbar/menu button or hotkey, you could also run the Rename command twice, with different regex, and avoid scripting. The Rename dialog can generate those commands for you (use the Clipboard button/menu at the bottom), and you'd just want to add the NOMATCHNOFAIL argument to the two commands, so they doesn't skip files which fail the first regex.

Try this:

Old name: (.+? - )?(.+)$
New name: your prefix - \2

Works for me.

(...and you don't even have to type it yourself. :wink: )

I agree with Leo, though. Those are two completely different filenames and it's not really necessary to deal with both of them in one expression.

This is exactly what I needed, MartO. Thank you.

And thanks, Leo.

I still want to improve upon on this further, if possible, but that's for another time.