Define parts of a name as a numeric value? Or how to choose what not to replace?

Advanced Renamer forum
#1 : 11/12-20 16:09
Asger H
Asger H
Posts: 2

What a great tool!
I've managed to Do a few useful things on a batch of filenames, but I need a bit of input on how to define different parts of a filename.
I've tried to read through the forum, but find a matching case.

I have a list of items named like this:
KT13043_4007 TAG1 TAG2 mix_3-21_2.jpg
Needs to be:

KT13043_4007 TAG1 TAG2 mix_3-21_F.jpg
Needs to be:

KT will be present in every filename.
13043_4007 and TAG1 TAG2 mix_3-21_ will be changing for every two files.

So basically, on every second file, I want to tell "Advanced renamer" to delete everything after "numericvalue_numericvalue"

And on the other half of the files to tell "Advanced renamer" to delete everything between "numericvalue_numericvalue" and "_F"

And that goes way above my skills :-)

Please help

11/12-20 16:09 - edited 11/12-20 17:23
#2 : 12/12-20 01:59
David Lee
David Lee
Posts: 1071
Harder than I expected!
There is probably a better solution but this works with your examples...

Replace: KT\d*_\d*\K.*(_F$)|KT\d*_\d*\K.*
With: \1
Use Regular expressions

12/12-20 01:59
#3 : 12/12-20 12:37
David Lee
David Lee
Posts: 1071
Reply to #2:
A simpler solution...

Replace: KT[^ ]*\K.*((_\D)|_\d)
With: \2

or without checking that the filename begins with "KT"...

Replace: [^ ]*\K.*((_\D)|_\d)
With: \2

"\K" isn't defined in the User Guide. It indicates that the preceding characters are necessary but will not be included in the final match - so that the characters before the first space will be retained.

"((_\D)|_\d)" means match either "_"+ "non-digit" or "_" + "digit". The parentheses define what will be saved in the variables \1, \2 etc. The outer parentheses indicate that either option (ie "_F" or "_2") will be saved in \1 and (_\D) that "_F" only will be saved in \1.

Adding another pair of parentheses - "((_\D)|(_\d))" would also save "_2" as \2.

12/12-20 12:37 - edited 12/12-20 15:08
#4 : 13/12-20 13:11
David Lee
David Lee
Posts: 1071
Reply to #3:
Better still: simply "[^ ]*\K.*[^(_F)]"

I thought that I had tried this regex first and it didn't work - I must have mistyped it.!

13/12-20 13:11
#5 : 14/12-20 09:18
Asger H
Asger H
Posts: 2
Reply to #4:

Thanks a LOT for your suggestions.
Can't wait to try them on the full list.
Crossing my fingers :-)

I'll get back and tell how it went.

14/12-20 09:18