python - String filtering commas and numbers -
i want filter string in python, commas ,
, numbers [0-9]
.
import re x="$hghg54646jhgjh,54546654" m=re.sub("[^0-9]","",x) print(m)
the result is:
5464654546654
instead of:
54646,54546654
with current code, match [0-9]
. add comma ,
valid character, , use backslash escape literal (\,
):
import re x="$hghg54646jhgjh,54546654" m=re.sub("[^0-9\,]","",x) print(m)
outputs:
54646,54546654
the docs have further information regarding other special characters must escaped backslash acquire literal, such ?
, *
.
Comments
Post a Comment