This is not a job for regex. As I pointed out in my comment, nested structures are usually beyond what regex can do. PCRE has the recursion construct (?R)
and .NET has balanced groups, but the solution usually get really unreadable and unmaintainable.
Added to that, you don't just have to take {}
into account, but strings and comments in your script as well. You are much better off, parsing the thing manually. Here is a quick and dirty example how it would be done using PHP (ignoring strings and comments!):
$level = 0;
$values = array();
$start = 0;
for($i = 0; $i < strlen($str); $i++)
{
switch($str[$i])
{
case ",":
if(!$level) {
$values[] = substr($str, $start, $i-$start);
$start = $i+1;
}
break;
case "{":
$level++;
break;
case "}":
$level--;
if($level < 0) trigger_error("unexpected }");
break;
}
}
if($level > 0) trigger_error("missing }");
$values[] = substr($str, $start);
You can see already, that you basically end up with a simpler parser for your script.