I need to find the space after 3 or 4 digits in a bunch of filenames and replace the space with an underscore. But I can't seem to even find 4 digits together.
s = "the blue dog and blue cat wore blue hats"
p = re.compile(r'blue (?P<animal>dog|cat)')
print(p.sub(r'gray \g<animal>',s))
#Gives basically what I want.
the gray dog and gray cat wore blue hats
s = "7053 MyFile.pptx"
p = re.compile('[0-9][0-9][0-9][0-9](?P<dig> )')
print(p.sub('_\g<dig>', s))
#Takes out the numbers, which I need to keep
_ MyFile.pptx
Everything I seem to do has the expression taking out the digits, which I need to keep.
In the end, I want
7035 MyFile.pptx
to be
7035_MyFile.pptx
"_".s.replace(' ', '_')?