python正则替换非数字字符源码演示

2023-06-28,,

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

#!/usr/bin/python
import re

phone = "2004-959-559 # This is Phone Number"

# Delete Python-style comments
print "Phone Num : ", num

# Remove anything other than digits
num = re.sub(r'D', "", phone)    
print "Phone Num : ", num

执行结果如下

Phone Num :  2004-959-559
Phone Num :  2004959559

《python正则替换非数字字符源码演示.doc》

下载本文的Word格式文档,以方便收藏与打印。