Matcher.find split , , for , ( ):
import java.util.*;
import java.util.regex.*;
public class StringSplit {
public static void main(String args[]) {
ArrayList<String> result = new ArrayList<String>();
for (Matcher m = Pattern.compile("..").matcher("12345"); m.find(result.isEmpty() ? 0 : m.start() + 1); result.add(m.group()));
System.out.println( result.toString() );
}
}
EDIT1
match(): , , BONUS_REGEX, Matcher, , (.. ), , , .. (. ). BONUS_REGEX "(.\\G.|^..)", , , \G -anchor-in-the-middle Java Match ( Perl):
perl -e 'while ("12345"=~/(^..|.\G.)/g) { print "$1\n" }'
12
23
34
45
split(): INSERT_REGEX_HERE (?<=..)(?=..) ( - , ), , split , [12, 3, 45] ( , .)
EDIT2
split(), , , ( ):
Pattern.compile("((?<=.).(?=.))").matcher("12345").replaceAll("$1#$1").split("#")
, , ( look-back) ; , ( ), , :
Pattern.compile("((?<=.).(?=.))").matcher("12345").replaceAll("$1$1").split("(?<=..)(?=(..)*$)")
match() ( ):
Matcher m = Pattern.compile("..").matcher(
Pattern.compile("((?<=.).(?=.))").matcher("12345").replaceAll("$1$1")
);
while (m.find()) {
System.out.println(m.group());
} // prints "12", "23", "34", "45"