字符串消息以bullet-in开头需要在nextLine中

时间:2014-04-24 16:01:59

标签: java regex string

我有字符串消息,其中包含如下信息。

这里我试图在行以数字后跟。(句号)

时溢出消息
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";

想要输出

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

尝试了很多方法。但没有运气

2 个答案:

答案 0 :(得分:1)

您可以使用:

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);

答案 1 :(得分:0)

使用regex

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);
}