python

Python - regex , remove all single characters,replace all single chars,char

# remove all single characters
# replace all single chars,char
import re

text = "That is a           test for removing                         multiple spaces"

document = re.sub(r's+[a-zA-Z]s+', ' ', text)

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

Remove all single characters with Space that we specify in regex expression

Was this helpful?