如何使用RegEx查找包含3个相同,连续字母的所有单词?

Noa*_*ser 2 regex

我有一个文字,让我们说:

Ich gehe auf die Donau und mache eine tolleSchifffahrtwährendichNussschalen esse.

所以现在,我想要找到包含3个相同连续字母的所有单词.在我的情况下,这将是:

Schifffahrt

Nussschale

我在RegEx方面没有很多经验,所以我非常感谢帮助.我为你打开了一个regex101页面.

非常感谢你.(对于那些想要知道为什么我需要一些奇怪的东西的人:有些原因我喜欢这个带有3个相同字母的单词,因为它们很少见.所以我想我编写一个机器人,它要求网站,阅读内容,并保存和输出所有找到的带有3个相同字母的单词.很好,不是吗?:))

anu*_*ava 8

你可以使用这个正则表达式:

\b\w*(\w)\1\1\w*
Run Code Online (Sandbox Code Playgroud)

RegEx演示

RegEx分手:

\b    # word boundary
\w*   # match 0 more word chars
\w    # match a word char and capture it as group #1
\1\1  # match 2 more instances of group #1
\w*   # match 0 more word chars
Run Code Online (Sandbox Code Playgroud)

  • 你不需要尾随的`\ b` - 它是前面贪婪的`\ w*`所暗示的 (3认同)
  • @Bohemian 你现在很_贪婪_:P (2认同)
  • @Bohemian使用前导词边界regex101显示422步,在示例演示中没有759步. (2认同)