String original = "This is a sentence.Rajesh want to test the application for the word split.";
List matchList = new ArrayList();
Pattern regex = Pattern.compile(".{1,10}(?:\s|$)", Pattern.DOTALL);
Matcher regexMatcher = regex.matcher(original);
while (regexMatcher.find()) {
matchList.add(regexMatcher.group());
}
System.out.println("Match List "+matchList);
我需要将文字解析成一系列行, 长度不超过10个字符, 并且不会在行末出现字断字 。
我在我的假想中使用了低于逻辑的逻辑,但问题在于,如果在行尾出现间断,则在10个字符之后将问题解析到最接近的白色空间。
例如: 实际的句子是“ < enger> this is a mental. Rajesh 想要测试单词分割的应用程序 。 strong > 。” 但在逻辑执行后, 它的步调如下 。
匹配列表 [这是一个, ince. Rajesh, 想要, 测试, 应用, 用于, 单词, 拆分 。 ]