Remove the last x characters in a certain condition

Bulk Rename Utility How-To's

Remove the last x characters in a certain condition

Postby Hughso2 » Fri Nov 21, 2025 9:27 pm

Hello all,

I have a set of 2000 Pdf files that are named Fname Lname_Certificate-num_DOB_counter.PDF In some cases there is an extra _ Counter.pdf. I would like to remove the second _Counter it is consistently the 4th underscore. I am thinking that a regex might work but looking for some ideas.

Thank you in advance
Ian
Hughso2
 
Posts: 3
Joined: Thu Sep 04, 2025 10:37 pm

Re: Remove the last x characters in a certain condition

Postby Hughso2 » Fri Nov 21, 2025 11:34 pm

Al;
Sorry I figured it out. It was more straightforward than I had originally thought.

I used the replace *_*_*_*_* with *_*_*_*

Thank you
Ian
Hughso2
 
Posts: 3
Joined: Thu Sep 04, 2025 10:37 pm

Re: Remove the last x characters in a certain condition

Postby Admin » Fri Nov 21, 2025 11:44 pm

Hi Ian,

yes, that's it, and you could also do it this way:

Use Simple mode with a match that captures the name segments around the 4th underscore and a replace that drops that 4th segment.

Example (turn on RegEx (1) -> Simple):

- Match: %1_%2_%3_%4_%5
- Replace: %1_%2_%3_%5

What this does
- %1 = everything up to the 1st underscore
- %2 = between 1st and 2nd underscore
- %3 = between 2nd and 3rd underscore
- %4 = the 4th segment you want to remove
- %5 = the rest (after the 4th underscore)
- Replace reassembles the name without the 4th segment (and without its underscore)

Notes and tips
- This works on the filename (not extension) — leave Inc. Ext. off unless you intentionally want to include the extension.
- If some files already lack a 5th segment, they will not match this pattern; test first on a selection.
- Test on a small subset and/or make a copy/backup before renaming 2,000 files.
- If you want to run a no-op for files that don’t have a 5th segment, you can preview selection and only apply to files that change, or use the multiple-RegEx editor to add additional rules if needed.

It is similar to the replace option.
Admin
Site Admin
 
Posts: 3118
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To


cron