如何使用python删除中文字符串中不连续的空白字符

如题所述

# 用正则
import re
str1 = 'hello wor ld \r\n'
str2 = re.sub(r'\s', '', str1) 

# 正则'\s' 表示空白字符, 包括空格、\r\n\t等..

print str2  # 输出 helloworld

温馨提示:答案为网友推荐,仅供参考
相似回答