替换非数字字符

mRt*_*mRt 10 python regex string

我需要从字符串中替换非数字字符.

例如,"8-4545-225-144"需要为"84545225144"; "$ 334fdf890 == - "必须是"334890".

我怎样才能做到这一点?

Ign*_*ams 18

''.join(c for c in S if c.isdigit())
Run Code Online (Sandbox Code Playgroud)


ken*_*ytm 17

正则表达式是可能的.

import re

...

return re.sub(r'\D', '', theString)
Run Code Online (Sandbox Code Playgroud)