python

Python - regex , replace multiple spaces with one space

# Substituting multiple spaces with single space
# replace multiple spaces with one space
# delete spaces
# spaces delete 
# tabs replace with one space 
# tow ore more spaces betwen words 
import re

text = "That is a           test for removing                         multiple spaces"
document = re.sub(r's+', ' ', text, flags=re.I)

print(document)
Output
That is a test for removing multiple spaces

Substituting multiple spaces with single space replace multiple spaces with one space delete spaces delete tabs replace with one space  tow ore more spaces between words 

Was this helpful?