replace last instance of a character only if...

Bulk Rename Utility How-To's

replace last instance of a character only if...

Postby wfejessie » Mon Jan 31, 2022 6:58 pm

Is it possible to replace the last instance of a character? And if it is, is it possible to replace it only if the file name ends in a hyphen & number? Example:
CER-1234
CER-1234-G
CER-1234-WG
CER-1234-1
CER-1234-G-1
CER-1234-WG-1
The first 3 should not be changed. On the last 3, the -1 should be changed to _1.
wfejessie
 
Posts: 2
Joined: Fri Aug 14, 2020 6:01 pm

Replace ending -# with _#

Postby Luuk » Mon Jan 31, 2022 7:19 pm

With RegEx(1), the "Match" and "Replace" can be like...
(.+)-(\d)$
\1_\2
Luuk
 
Posts: 704
Joined: Fri Feb 21, 2020 10:58 pm

Re: replace last instance of a character only if...

Postby Admin » Tue Feb 01, 2022 2:10 am

Aos, with the Javascript renaming you could write a Javascript routine that can get as complex as needed. 8)
Admin
Site Admin
 
Posts: 2354
Joined: Tue Mar 08, 2005 8:39 pm


Return to How-To