remove trailing and leading spaces in python regex code example Example: python remove spaces string=' t e s t ' print(string.replace(' ',''))