test_str = "a.. x what! he was a in the U.S.A.F but in the accounts dept?"
我们需要删除所有非单词,除了已经分隔单词的单个空格和首字母缩略词中的句点。
结果应如下所示:
a x What he was in the U.S.A.F but in the accounts dept
.
我试过:用 9 代替可见性
re_result = re.sub(pattern = r"(?<=\W)[\W][\S](?=\W)", repl= '9', string=test_str, count=0, flags=0)
我得到:
a..9 what! he was a in the U.S.A.F but in the accounts dept?
r"(?<=\W)[\W][\S](?=\W)|\b\W\b"
不起作用。感谢您的时间和帮助