python - Remove period[.] and comma[,] from string if these does not occur between numbers -


i want remove comma , period text when these not occur between numbers.

so, following text should return

"this shirt, nice. costs dkk ,.1.500,00,."  "this shirt nice costs dkk 1.500,00" 

i tried

text = re.sub("(?<=[a-z])([[$],.]+)", " ", text)  

but not substitute in text.

you try this:

>>> s = "this shirt, nice. costs dkk ,.1.500,00,." >>> re.sub('(?<=\d)[.,]|[.,](?=\d)', '', s) 'this shirt nice costs dkk 1.500,00' 

using positive lookbehind assertion check symbols preceded non digit character, , alternation on same character set using positive lookahead assertion check followed non digit character.

https://regex101.com/r/54stmm/4


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -