I don't always understand so make a note
import re
text = "I want to erase these ← half-width spaces and ← full-width spaces, but leave one."
text = re.sub('[ ]+', ' ', text)
print(text)
'I want to erase these ← half-width spaces and ← full-width spaces, but leave one.'
If you specify the space
re.sub ('[(half-width space) (full-width space)] +',' (half-width space)', text)
It's like that.
Recommended Posts