Say I have
text = "El próximo AÑO, vamos a salir a Curaçao... :@ :) será el día #MIÉRCOLES 30!!!!"
How can I turn it into
text2 = "El próximo AÑO vamos a salir a Curaçao será el día MIÉRCOLES 30"
Using regex?
Say I have
text = "El próximo AÑO, vamos a salir a Curaçao... :@ :) será el día #MIÉRCOLES 30!!!!"
How can I turn it into
text2 = "El próximo AÑO vamos a salir a Curaçao será el día MIÉRCOLES 30"
Using regex?
You can try using the \W
character class:
re.sub(r'\W+', ' ', text)
If you need compatibility with Python 2.7 you can use the str.isalpha()
method:
# -*- coding: utf-8 -*-
import re
text = u"El próximo AÑO, vamos a salir a Curaçao... :@ :) será el día #MIÉRCOLES 30!!!!"
print(re.sub(' +', ' ', ''.join(c for c in text if c.isalpha() or c.isdigit() or c.isspace())))
This outputs:
El próximo AÑO vamos a salir a Curaçao será el día MIÉRCOLES 30