0

下面是我的文字

This is my first java Program. I am new to java program. but my program is successfully running without any. issues. Thanks to all

它应该像

This is my first java Program.
I am new to java program. but my program is successfully running without any. issues.
Thanks to all.

正则表达式应采用以下模式

1.dot
2.followed by space
3.followed by capital letter word(not lowecase)

我试过这个

  1. \\.\\w[A-Z]
  2. \\.\\s\s[A-Z]
  3. \\.(?!\\w)

但未能得到它。

4

2 回答 2

2

试试下面的代码:

String text = "This is my first java Program. I am new to java program. but my program is successfully running without any. issues. Thanks to all";
Pattern pattern = Pattern.compile("(?<=\\.)\\s+(?=[A-Z])");
String[] lines = pattern.split(text);
for (String line : lines) {
    System.out.println(line);
}

输出:

This is my first java Program.
I am new to java program. but my program is successfully running without any. issues.
Thanks to all
于 2013-08-08T05:28:12.823 回答
0

使用 String.split() 方法拆分您的字符串(返回一个数组)。

阅读此处以了解 java 的正则表达式。

于 2013-08-08T05:24:43.067 回答