I've been working on this file rename program for a few days now. I've learned a lot thanks to all of the "silly" questions those before me have asked on this site and the quality answers they have received. Well, on to my problem.
My filenames are in the following format: ACP001.jpg, ACP002.jpg,... ACP010.jpg, ACP011.jpg, ACP012_x.jpg, ACP013.jpg, ACP014_x.jpg
pattern = r'(ACP0)(0*)(\d+)(\.jpg)'
replace = r'\3\4'
So that was working fine for most of them... but then there were some that had the "_x" just before the file extension. I ammended the pattern and replacement pattern as follows
pattern = r'(ACP0)(0*)(\d+)(_w)*(\.jpg)'
replace = r'\3.jpg'
I think I cheated by hardcoding the ".jpg" in the replace string. How would I handle these situations where the match object groups may be of varying sizes? I essentially want the last group and the third group in this example.