Removing 2 digit hyphen delimited value

Bulk Rename Utility How-To's

Removing 2 digit hyphen delimited value

Postby Mattbru » Sun Jul 26, 2020 1:08 pm

I have a number of variable length files, where I need to remove a 2 digit numeric value and the following "-"

This is what I have:

filenamealpha-01-02-hfjdksahfds
filenamebravo-02-02-fdsfadsfds
filenamecharlie-03-02-hgfhgfg
filenamedelta-04-02-hgfhersdf

I want to remove the 02- from each file, giving me below:

filenamealpha-01-hfjdksahfds
filenamebravo-02-fdsfadsfds
filenamecharlie-03-hgfhgfg
filenamedelta-04-hgfhersdf

I would normally do this by replacing "02-" with a space, effectively removing it.

The only problem with this particular example, is that the "02-" that I am removing, appears twice in some of the files. (I only want to remove the one occurrence that appears later in the file).

I am wondering if there is a way I can specify only replace the 02- that is followed by an alphabetic field.

An alphabetic wildcard would do the job.

Any suggestions (or a completely different method) would be welcomed.
Mattbru
 
Posts: 2
Joined: Thu Apr 24, 2008 3:26 am

Re: Removing 2 digit hyphen delimited value

Postby therube » Sun Jul 26, 2020 1:29 pm

1:RegEx
Code: Select all
Match:  (.*)(-02)(.*)
Replace:  \1\3

Match everything
up the the final instance of -02
Match everything else

Keep all, except for that -02 instance.

filenamebravo-02-02-fdsfadsfds
-> filenamebravo-02-fdsfadsfds


Note:

filenamebravo-02-fdsfadsfds
-> filenamebravo-fdsfadsfds
and
filenamebravo-02-01-fdsfadsfds
-> filenamebravo-01-fdsfadsfds

So if something like that potentially exits, you'd want to change what you're searching for in the Match: a bit.


This is likely a more robust Match:
Code: Select all
Match: (.*-\d\d)(-02)(.*)


Yeah, that should be better.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to How-To