Reading Time: 1 minutes
Remove excessive spacing from a string in Python
Write a Regular Expression in Python to remove excessive spacing from a string.
Remove excessive spacing from a string
import re
sourceString = 'this is a string with excessive spacing.'
print( re.sub('\s+', ' ', sourceString) ) # 'this is a string with excessive spacing.'
To learn more about Regular Expressions in Python, click here.







