python 替换所有的非特殊字符

替换所有的字符:

\w 匹配非特殊字符,即a-z、A-Z、0-9、_、汉字 


node2:/root/python3#cat in.txt
abc,jjd12,!3323$%%^&

node2:/root/python3#cat t8.py 
import time
import re
with open('in.txt', 'r') as fin:    
   text = fin.read()
   text = re.sub(r'\w', ' ', text) 
   print(text)
   #text = re.sub(r'[^\w ]', ' ', text) 
node2:/root/python3#python3 t8.py 
   ,     ,!    $%%^&

node2:/root/python3#

 

你可能感兴趣的:(python,进阶)