Python: Replace "wrong" floats by integers inside string -
i'm trying replace useless floats in string (1.0, 2.0 etc.) integers. i'd turn string "15.0+abc-3"
"15+abc-3"
. know way that?
i hope understood idea. if didn't feel free ask.
(?<=\d)\.0+\b
you can simple use , replace empty string
via re.sub
.
see demo.
https://regex101.com/r/hi0qp0/22
import re p = re.compile(r'(?<=\d)\.0+\b') test_str = "15.0+abc-3" subst = "" result = re.sub(p, subst, test_str)
Comments
Post a Comment