re表达式替换掉"\n\t\r”字符

使用re来将一些字符替换掉,比如替换为空:

1 import re 
2 
3 s = "这是一个例子\n,我们的祖国"
4 re.sub("[\n\t\r]", "", s) 

非常方便地替换掉你需要替换或者取消的字符

猜你喜欢

转载自www.cnblogs.com/demo-deng/p/9634100.html