#!/bin/python
#site: www.jb200.com
#
import re
s = "how19 a*re 254y**ou?"
# Using regular expressions
print re.sub("D", "", s)
>>> crazystring = ‘dade142.;!0142f[.,]ad’
1,只保留数字
>>> filter(str.isdigit, crazystring)
‘1420142′
2,只保留字母
>>> filter(str.isalpha, crazystring)
‘dadefad’
3,只保留字母和数字
>>> filter(str.isalnum, crazystring)
‘dade1420142fad’
4,如果想保留数字0-9和小数点’.’ 则需要
自定义函数
>>> filter(lambda ch: ch in ‘0123456789.’, crazystring)
‘142.0142.’