Q:

Java Regex to Find Location of Differing Consecutive Characters

I have some String objects that I need to split into an array of substrings at the locations of differing consecutive characters.
My Input/Output should look like this:
"AAAA"    -> ["AAAA"]
"AAAABBB" -> ["AAAA", "BBB"]
"ABBCCC"  -> ["A", "BB", "CCC"]

I want to be able to write a line of code like this: 
String[] charRuns = str.split(regex);

Where str is the input and charRuns is the output, but what should the value of regex be?

A:

Can't find a way to do this with split yet, but here's a solution based on Pattern, Matcher and iteration:
String test = "ABBCCCDDDDE";
//                          | any character, grouped for back-reference
//                          | | immediate back-reference
//                          | |    | 0+ repetition, greedy
Pattern p = Pattern.compile("(.)\\1*");
Matcher m = p.matcher(test);
while (m.find()) System.out.println(m.group());

Output
A
BB
CCC
DDDD
E

