如何找出下列文字中出现的连续重复单词?

新手上路,请多包涵

如to to,have have have,tomorrow tomorrow等等,语句如下:

You’d better to to hit the hay early as you you have have have an important examination tomorrow tomorrow.

我尝试了

([a-z]+[ ])\1+

但是tomorrow tomorrow.无法匹配
2019-12-23_091332.jpg

尝试了

([a-z]+)[ ]\1+

但是重复三遍等have无法完全匹配,还把不该匹配的地方匹配了
2019-12-23_091446.jpg

初学正则表达式,求教,谢谢。

阅读 3.5k
4 个回答

\W?(?:(\w+)\W)(?:\1\W)+捕获组的第一个元素是整个字符串,第二个元素是重复的单词。