Java正则表达式,用于查找单词中两个或多个连续或不连续的点



知道句子中的一个单词有两个或多个连续或非连续点的最佳正则表达式是什么?

示例:

Non match:
This does not have a multiple dots. This is a normal line of sentences.
Match:
This should match because www.site.com has two dots.
This should also match since dot.andanotherdot. has two dots.
Consecutive dots like this ..dots is also matching.

我发现了很多可能与此相关的问题,但通常情况下,它们只需要找到连续的问题。或者他们需要在行中找到它,而不是通过逐词查找。

有3种情况:

  • 两个中间有字母的点
  • 前面有字母的两个连续点
  • 两个后面有字母的连续点

将所有3都写为regex,并使用|OR模式进行组合。

.p{L}+.|p{L}.{2}|.{2}p{L}

最新更新