Remove part of filename

Advanced Renamer forum
#1 : 31/12-22 15:30
JV
JV
Posts: 1
Hi there,

I've got some files I want to rename. They all contain 1 date, one or a few words, a counter, the old filename, an underscore, date, counter, time. See three examples below.

April 29 apple 01 blablabla bla blabla_220429_0020_1532u
May 04 carrot 03 random old filename_220504_0013_1215u
June 07 apple pie 03 old filename to remove_220607_0001_1317u

The length of the old filename can be anything, the same goes for the text between the date and the counter in the beginning. The last part, from the first underscore till the final 'u' always has the same length.

I want to remove the old filename and the underscore. New filenames should look like:
April 29 apple 01 220429_0020_1532u
May 04 carrot is stupid 03 220504_0013_1215u
June 07 apple pie 03 220607_0001_1317u

Can anyone of you help?
Thanks a lot.

Jeroen


31/12-22 15:30 - edited 31/12-22 16:03
#2 : 04/01-23 15:35
David Lee
David Lee
Posts: 1125
I'm assuming that adding " is stupid" to "carrot" in your second example was an error.

If so, use a "Remove pattern" method with the following regular expression:

^\w+ \d{2}[^\d]*\d+ \K[^_]+_

Explanation:

"^\w+ " matches one or more word characters followed by a space"

"\d{2}" adds the following two digits to the match

"[^\d]*\d+ " matches any number of non-digit characters followed by one or more digits and a space

"\K" is then an instruction to forget all the characters matched up to this point

Finally "[^_]+_" matches a string of one or more non-underscore characters followed by a single underscore - ie the string you want to remove.



04/01-23 15:35