import re
x = "this is is a desk"
pattern = re.compile(r'\b(\w+)(\s+\1){1,}\b')
matchResult = pattern.search(x)
x = pattern.sub(matchResult.group(1), x)
print(x)
python3用正则表达式过滤重复单词
最新推荐文章于 2023-03-22 08:49:48 发布
import re
x = "this is is a desk"
pattern = re.compile(r'\b(\w+)(\s+\1){1,}\b')
matchResult = pattern.search(x)
x = pattern.sub(matchResult.group(1), x)
print(x)