regextotal-commander

how to eliminate dots from filenames, except for the file extension


I have a bunch of files that look like this:

A.File.With.Dots.Instead.Of.Spaces.Extension

Which I want to transform via a regex into:

A File With Dots Instead Of Spaces.Extension

It has to be in one regex (because I want to use it with Total Commander's batch rename tool).

Help me, regex gurus, you're my only hope.

Edit

Several people suggested two-step solutions. Two steps really make this problem trivial, and I was really hoping to find a one-step solution that would work in TC. I did, BTW, manage to find a one-step solution that works as long as there's an even number of dots in the file name. So I'm still hoping for a silver bullet expression (or a proof/explanation of why one is strictly impossible).


Solution

  • Here's one based on your almost-solution:

    /\.([^.]*(\.[^.]+$)?)/\1/
    

    This is, roughly, "any dot stuff, minus the dot, and maybe plus another dot stuff at the end of the line." I couldn't quite tell if you wanted the dots removed or turned to spaces - if the latter, change the substitution to " \1" (minus the quotes, of course).

    [Edited to change the + to a *, as Helen's below.]