[Python] python正则替换非数字字符代码演示 →→→→→进入此内容的聊天室

来自 , 2019-04-06, 写在 Python, 查看 154 次.
URL http://www.code666.cn/view/551fdbb8
  1. #!/usr/bin/python
  2. import re
  3.  
  4. phone = "2004-959-559 # This is Phone Number"
  5.  
  6. # Delete Python-style comments
  7. num = re.sub(r'#.*$', "", phone)
  8. print "Phone Num : ", num
  9.  
  10. # Remove anything other than digits
  11. num = re.sub(r'\D', "", phone)    
  12. print "Phone Num : ", num
  13.  
  14.  
  15. #//python/8342

回复 "python正则替换非数字字符代码演示"

这儿你可以回复上面这条便签

captcha