在 test.txt 中:
quiet confidence^_^
want:P
(:let's start
代码:
import re
file = open('test.txt').read()
for line in file.split('\n'):
line = re.findall(r"[^\w\s$]+|[a-zA-z]+|[^\w\s$]+", line)
print " ".join(line)
结果显示:
quiet confidence^_^
want : P
(: let ' s start
我试图将一组特殊字符与字符串分开,但仍然不正确。有什么建议吗?
预期成绩:
quiet confidence ^_^
want :P
(: let's start