Use a lookahead for Input
and use find
in a loop, instead of matches
:
Pattern pattern = Pattern.compile("Input(.*?)(?=Input|$)");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
System.out.println(matcher.group(1));
}
See it working online: ideone
But it's better to use split here:
String[] result = s.split("Input");
// You need to ignore the first element in result, because it is empty.
See it working online: ideone
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…