I want to remove comma and period from a text only when these does not occur between numbers.
So, following text should return
"This shirt, is very nice. It costs DKK ,.1.500,00,."
"This shirt is very nice It costs DKK 1.500,00"
text = re.sub("(?<=[a-z])([[$],.]+)", " ", text)
You could try this:
>>> s = "This shirt, is very nice. It costs DKK ,.1.500,00,." >>> re.sub('(?<=\D)[.,]|[.,](?=\D)', '', s) 'This shirt is very nice It costs DKK 1.500,00'
Using a positive lookbehind assertion to check the symbols are preceded by a non digit character, and an alternation on the same character set using a positive lookahead assertion to check it is followed by a non digit character.