把內容過程中比較重要的一些內容段備份一次,下面內容段是關於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