Q:

java extract elements separated by comma from a String

I have a string like this:
String input= 'hello',2,[5,6],'city'. 

So the string is composed by different kind of elements. 
I "simply" need to extract the elements separated by comma.  However i cannot find
a method to avoid to consider the comma into the element [5,6]. 
I tried by using the split() method and considering many different regex to
reach my goal, without success. 

A:

,(?![ ^\[]*[]]) works for the job. 
class Test {
    public static void main(String[] args){

        String test = "'hello',2,[5,6],'city'";
        String[] output = test.split(",(?![^\\[]*[]])");

        for (String s : output)
            System.out.println(s);

    }
}

Output:
'hello'
2
[5,6]
'city'

