先行使用Input
并find
在循环中使用,而不是matches
:
Pattern pattern = Pattern.compile("Input(.*?)(?=Input|$)");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
System.out.println(matcher.group(1));
}
看到它在线上工作:ideone
但是最好在这里使用split:
String[] result = s.split("Input");
// You need to ignore the first element in result, because it is empty.
看到它在线上工作:ideone