以下是我的文字
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)
我试过这个
\\.\\w[A-Z]
\\.\\s\s[A-Z]
\\.(?!\\w)
但未能得到它。
答案 0 :(得分: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
答案 1 :(得分:0)
使用String.split()方法拆分字符串(返回一个数组)。
阅读here以了解java的正则表达式。