Java 以项目符号开头的字符串消息需要在下一行中

Java 以项目符号开头的字符串消息需要在下一行中,java,regex,string,Java,Regex,String,我有一个字符串消息,它包含如下消息 在这里,我试图在以数字开头,后跟(句号)的时候将消息溢出 想要像这样的输出吗 1.Hi this is test 2. this is also test 3. this is also test 4. this is also test 5. this is also test 尝试了很多方法。但是没有运气使用 您可以使用以下选项: String str="1. Hi this is test 2. this is also test 3. this is

我有一个字符串消息,它包含如下消息

在这里,我试图在以数字开头,后跟(句号)的时候将消息溢出

想要像这样的输出吗

1.Hi this is test
2. this is also test
3. this is also test
4. this is also test
5. this is also test
尝试了很多方法。但是没有运气

使用

您可以使用以下选项:

String str="1. Hi this is test 2. this is also test 3. this is also test 4. this
is also test 5. this is also test";

Pattern regex = Pattern.compile("[\\d]+\\.[a-z ]+", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
Matcher regexMatcher = regex.matcher(str);

您能告诉我们您尝试过的“多种”方法中的至少一种吗?Pattern.compile(“.*\\D.”);。匹配任何字符。您需要转义它(使用\\或使用Pattern.quote())。也\\D表示不是数字。你确定这就是你想要的吗?
String str="1. Hi this is test 2. this is also test 3. this is also test 4. this is also test 5. this is also test";

for(String s : str.split("(?=\\d.)")) {
        System.out.println(s);
}
String str="1. Hi this is test 2. this is also test 3. this is also test 4. this
is also test 5. this is also test";

Pattern regex = Pattern.compile("[\\d]+\\.[a-z ]+", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
Matcher regexMatcher = regex.matcher(str);