Is there a regex that would work with String.split()
to break a String into contiguous characters - ie split where the next character is different to the previous character?
Here's the test case:
String regex = "your answer here";
String[] parts = "aaabbcddeee".split(regex);
System.out.println(Arrays.toString(parts));
Expected output:
[aaa, bb, c, dd, eee]
Although the test case has letters only as input, this is for clarity only; input characters may be any character.
Please do not provide "work-arounds" involving loops or other techniques.
The question is to find the right regex for the code as shown above - ie only using split()
and no other methods calls. It is not a question about finding code that will "do the job".
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…