python正則替換非數字字符源碼演示

把內容過程中比較重要的一些內容段備份一次,下面內容段是關於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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章