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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -