把内容过程中比较重要的一些内容段备份一次,下面内容段是关于python正则替换非数字字符演示的内容,应该对码农们有用途。

#!/usr/bin/pythonimport rephone = "2004-959-559 # This is Phone Number"# Delete Python-style commentsprint "Phone Num : ", num# Remove anything other than digitsnum = re.sub(r'D', "", phone) print "Phone Num : ", num执行结果如下Phone Num : 2004-959-559Phone Num : 2004959559