Removing all non-numeric characters from string in Python

后端 未结 7 1044
遥遥无期
遥遥无期 2020-11-29 17:42

How do we remove all non-numeric characters from a string in Python?

相关标签:
7条回答
  • 2020-11-29 18:12

    @Ned Batchelder and @newacct provided the right answer, but ...

    Just in case if you have comma(,) decimal(.) in your string:

    import re
    re.sub("[^\d\.]", "", "$1,999,888.77")
    '1999888.77'
    
    0 讨论(0)
提交回复
热议问题