I have the following spanish sentence.
Oye , si te parece quedamos en El Corte Inglés de Nuevos Ministerios este martes , a las 18:30 , y me ayudas con las compras , te parece los sofás no sé si comprarlos en Zara Home o en la web , que es http://zara-home.es . De todas maneras , dame un toque al +00 000 000 000 y lo hablamos. Te dejo también mi correo , username@domain .com. Venga , hasta luego.
From this sentence, I want to remove the spaces between 'words and commas' and 'words and fullstops'. I am using the following code to do this job. It works for most other sentences, But do not work for the said sentence.
sentence = 'Oye , si te parece quedamos en El Corte Inglés de Nuevos Ministerios este martes , a las 18:30 , y me ayudas con las compras , te parece los sofás no sé si comprarlos en Zara Home o en la web , que es http://zara-home.es . De todas maneras , dame un toque al +00 000 000 000 y lo hablamos. Te dejo también mi correo , username@domain .com. Venga , hasta luego.'
full_stop = re.compile(u"(?<=\s)([\w\d\@\-\:\/\.]+\s[\.,])", re.UNICODE)
words_changed = ["".join(full_stops.split()) for full_stops in full_stop.findall(sentence)]
for i,words in enumerate(full_stop.findall(sentence)):
words = re.sub('\s.','\s\.',words, flags=re.UNICODE)
sentence = re.sub(words, words_changed[i], sentence, flags=re.UNICODE)
print sentence
Why does the re.sub do not always act, the way it is supposed to in python?