I'm using the following function to remove a specific string pattern from files in a directory:
import os
for filename in os.listdir(path):
os.rename(filename, filename.replace(r'^[A-Z]\d\d\s-\s[A-Z]\d\d\s-\s$', ''))
The pattern is as follows, where A is any capital letter, and # is any number between 0-9:
A## - A## -
My regex matches this format on regex101. When I run the above function, it completes without error, however no directory names change. Where am I going wrong?