Python 正则表达式练习

美女发来的电话号码是这样的尴尬

想个办法让他变清爽。


#coding=utf-8
import re
phone = "1*5*1*1*0*3*3*6*4*9*1 #美女发来的电话号码"

# delete python-style comments
num =re.sub(r'#.*$',"",phone)
print "phone num:",num

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


你可能感兴趣的:(python,正则表达式)