[Krename] Find and replace last digit ONLY from file extension and NOT from filename

I have a directory full of files like ‘filename1.png0’ that I would like to turn into ‘filename1.png’ as an example. The numbers in the actual filename can stay, but I want the number at the end of the filename to go.

I was using regular expressions in the Find and Replace dialog to try and accomplish this, but I haven’t been able to find a way to make my modification only from the extension. The regex I was using was this, among a few others I was experimenting with:

\d(?=\D*$)

regex101.com suggests that this should work to only select the final digit in the extension and NOT the filename itself, but it in krename I receive ‘filename.png’. It removes the final numbers from both the filename and extension, which isn’t what I need.

Is there an option I’m missing, is my expression incorrect, or is this currently not a feature of the program?

Try this:

  1. Change the “File extension starts at:” setting to “No File Extension”. This tells KRename not to try to distinguish “the filename itself” from “extension”, because we’ll take care of that in our regex.
  2. In “Find and Replace”, add this pattern:
  • Find: (.*\.)(.*)(\d+)
  • Replace With: \1\2
  • make sure that the “Find is a Regular Expression” box is checked

The rationale is that Group 1 is the filename itself plus the dot; Group 2 is the non-digit part of the extension; Group 3 is the digit part of the extension. We keep \1 and \2 and we throw away \3.

(If you literally want to remove only the final digit, i.e. you want to rename filename2.mp31 to filename2.mp3, then just use (\d) in place of (\d+) in the regular expression.)

This works for me -