I have some string patterns. Each pattern consist of two characters "A" and "B". My patterns are like "AA" or "ABA" or "AABBABA" or ...
I want to split these patterns and the output for these examples must be like: {"AA"} or {"A","B","A"} or {"AA","BB","A","B","A"}
What I tried so far :
String pattern = "AABBABA" //or whatever
String firstChar = pattern.toString().substring(1, 2);
String[] split = pattern.split(firstChar);
for (String string : split) {
Log.i("findPattern", "Splitted Pattern: " + string + "");
}
The problem with my code is that it removes all strings that are equal to firstChar
.
What regular expression should I use to split my patterns to separated strings?