小编Gan*_*nz7的帖子

将段落拆分为单个句子.我在这里覆盖了所有的基地吗?

我正在尝试将包含多个句子的字符串拆分为单个句子的字符串数组.

这是我到目前为止所拥有的,

String input = "Hello World. " 
             + "Today in the U.S.A., it is a nice day! "
             + "Hurrah!"
             + "Here it comes... "
             + "Party time!";
String array[] = input.split("(?<=[.?!])\\s+(?=[\\D\\d])");
Run Code Online (Sandbox Code Playgroud)

这段代码工作得非常好.我明白了

Hello World.
Today in the U.S.A., it is a nice day!
Hurrah!
Here it comes...
Party time!
Run Code Online (Sandbox Code Playgroud)

我使用该lookbehind功能来查看结束标点符号的句子是先于某个还是单个white space(s).如果是这样,我们分手了.

但是这个正则表达式没有涵盖一些例外.例如, The U.S. is a great country被错误地拆分为The U.S.is a great country.

关于如何解决这个问题的任何想法?

而且,我在这里错过了任何边缘案例吗?

java regex

6
推荐指数
1
解决办法
247
查看次数

标签 统计

java ×1

regex ×1