change last instance if followed by number

Bulk Rename Utility How-To's

change last instance if followed by number

Postby wfejessie » Fri Aug 14, 2020 6:07 pm

If the last instance of a dash is followed by a number, I want to change a dash to an underscore. Examples:
CER-1234 no change
CER-1234-1 CER-1234_1
CER-1234-2 CER-1234_2
CER-1234-W no change
CER-1234-W-1 CER-1234-W_1
CER-1234-W-2 CER-1234-W_2
CER-1234-WG no change
CER-1234-WG-1 CER-1234-WG_1
CER-1234-WG-2 CER-1234-WG_2

The below works except it also changes the ones I don’t want changed (the ones followed by a letter). I don’t know how to specify only if the last dash is followed by a number:
Match: (.*)(-)(.*)
Replace: \1_\3

How do I specify to only change it if the last dash is followed by a number?
wfejessie
 
Posts: 2
Joined: Fri Aug 14, 2020 6:01 pm

Re: change last instance if followed by number

Postby therube » Sat Aug 15, 2020 4:49 pm

1:RegEx
Code: Select all
Match:  (.*)-(\d+)$
Replace:  \1_\2

Match anything up to the final dash, followed by 1 (or more) digits (at the end of the file name).
Replace the dash with an underline.
Code: Select all
CER-1234-123 ->
   CER-1234_123
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to How-To