Q:

regex to match comma delimited balanced square brackets having recursion

I'd like a regex to match comma-delimited, balanced square brackets where the contents of the square brackets might be comma-delimited balanced square brackets themselves.
Here are some examples:
example 1
input = "[abc],[def]"
groups 
    group 1 = "abc"
    group 2 = "def"

example 2
input = "[[ghi],[jkl]],[mno[pqr]],[[stu]]"
groups
    group 1 = "[ghi],[jkl]"
    group 2 = "mno[pqr]"
    group 3 = "[stu]"

So note that in the second example, "ghi" and "jkl" are not their own groups.  I don't need to recurse all the way down, I just need a regex to find the "level 0" groups.

A:

Here's some code that can get you started on how to parse those values out.
public static IEnumerable<string> SplitSquareBraketByComma(string input)
{
    int start = 0;
    int brakets = 0;
    for(int i = 0; i < input.Length; i++)
    {
        if(input[i] == '[') 
        {
            brakets++;
            continue;
        }

        if(input[i] == ']')
        {
            brakets--;
            continue;
        }

        if(brakets == 0 && input[i] == ',')
        {
            yield return input.Substring(start, i - start);
            start = i + 1;
        }
    }

    if(start < input.Length)
    {
        yield return input.Substring(start);
    }
}

It basically keeps count of the brackets and when it sees a comma when the number of open brackets is zero it splits out a new string from the previous split.  
Note: this does not have any code to check that the input is valid (having all balanced brackets) and thus it's leaving in the outer most brackets just in case.

