您好如何根据模式分割下面的文字
示例文字:
Overview This is my sample program Written in java
必需的输出
Overview
This is my sample program
Written in java
我尝试过以下正则表达式但没有工作
"\\s{2,}\\[A-z]"
请建议我使用正则表达式来分割我的文字
答案 0 :(得分:6)
使用正向期待((?=[A-Z])
)来匹配大写字母而不消耗:
String text = "Overview This is my sample program Written in java";
String[] words = text.split("\\s{2,}(?=[A-Z])");
for (String word : words)
System.out.println(word);
答案 1 :(得分:0)
String text = "Overview This is my sample program Written in java";
String[] words = text.split("\\s{2,}");
for (String word : words) {
System.out.println(word);
}
您不必使用积极的期待。