How to make Java String split greedy with lookahead?

Viewed 1227

Code is basically:

String[] result = "T&&T&T".split("(?=\\w|&+)");

I was expecting the lookahead to be greedy but instead it is returning the array:

T, &, &, T, &, T

What I am aiming for is:

T, &&, T, &, T

Is this possible for split and lookahead?

I have tried the following split regex values but the result is still not greedy for the ampersand:

"(?=\\w|&&?)"

"(?=\\w|&{1,2})"

4 Answers
Related