// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CamelSplitTest {
    private static Pattern re = Pattern.compile("([A-Z][a-z]+)|([A-Z]+(?=([A-Z][a-z]|[0-9]|$)))|([0-9]+)|(^[a-z]+)"); 
    public static List<String> camelSplit(String s) {
        List<String> res = new ArrayList<String>();
        Matcher m = re.matcher(s);
        while(m.find()) {
            res.add(m.group());
        }
        return res;
    }
    public static void test(String s) {
        List<String> parts = camelSplit(s);
        System.out.print(s + " ->");
        for(String part : parts) System.out.print(" " + part);
        System.out.println();
    }
    public static void main(String[] args) {
        String[] all = { "Test", "TestTest", "TestTest123", "TestTest123Test", "TestTest1Test2Test3Test", "TestTestTESTTest", "testTest" };
        for(String one : all) {
            test(one);
        }
    }
}
