There are a couple ways to tackle this.
I'd look at some simple looping to do it
object = "building012056floor261861carpet096321"
#using re.sub
import re
newname = re.sub(r'\d+', '', object)
print(newname)
#using
import re.sub but replacing the # with "_"
numbers = r"[0-9]"
newname = re.sub(numbers, '_', object)
print(newname)
#using the built in function of join (and a loop)
new_name = "".join((z for z in object if not z.isdigit()))
print(new_name)
#using a loop
# but this one will replace the numbers with "_"
new_name = ""
for n in object:
if n.isdigit():
b = "_"
else:
b = n
new_name += b
print(new_name)
or... ( and probably what you are looking for )
#using if elif else
# replace a string of numbers with just one underscore by checking... -1
object = "building012056floor261861carpet096321"
new_name = ""
for i,n in enumerate(object):
#print("i:{}, n:{}".format(i,n))
try:
if object[i-1].isalpha() and n.isdigit():
new_name += "_"
elif object[i-1].isdigit() and n.isdigit():
pass
else:
new_name += n
except:
pass
print(new_name)
-hth
-=s