Search code examples
regexbatch-filerenamefilenames

regex to change filenames


I'm sure there is a simple solution I'm missing here.

Please see below.

I need to rename these files basically by removing the preceding zero from the last section of the filename. It's tricking me when I hit double digits in the filename. (filename will never go above 99 in the last section).

original change to
MM_052823_A001 MM_052823_A01
MM_052823_A002 MM_052823_A02
MM_052823_A003 MM_052823_A03
MM_052823_A004 MM_052823_A04
MM_052823_A005 MM_052823_A05
MM_052823_A006 MM_052823_A06
MM_052823_A007 MM_052823_A07
MM_052823_A008 MM_052823_A08
MM_052823_A009 MM_052823_A09
MM_052823_A010 MM_052823_A10
MM_052823_A011 MM_052823_A11
MM_052823_A012 MM_052823_A12
MM_052823_A013 MM_052823_A13
MM_052823_A014 MM_052823_A14
MM_052823_A015 MM_052823_A15
MM_052823_A016 MM_052823_A16
MM_052823_A017 MM_052823_A17
MM_052823_B001 MM_052823_B01

Would greatly appreciate any leads on this! TIA!


Solution

  • You can isolate the last zero
    like this 0(\d+$)
    then replace with the capture group $1
    Use the Multiline Flag if doing several lines at a time.

    https://regex101.com/r/dXAk4D/1