使用键和值嵌套括号,PHP

I'm trying to get each nested square bracket separated into their own parts, and also recurred if there are any sub ests or square brackets, for example, i'm trying to turn:

 [a % 1][b % [a % 2]][c % 3]

Into:

Array
(
    [a] => 1
    [b] => Array
        (
            [a] => 2
        )
    [c] => 3
)

Edit,1

I guess what I'm really trying to do is:

Turn:

 [a % 1][b % [a % 2]][c % 3]

Into an array like this:

Array
(
  [0] => a % 1
  [1] => b % [ a % 2 ]
  [2] => c % 3
)

Using PHP. But, my regExp isnt working: /\[(.*)\]/ I know there may be a way to do this, but I cannot figure out how.

Here is my code, it works good, for recurring but it turns the first example, into:

Array
(
    [a] => 1
    [b] => [a%2
    [c] => 3
)

Here is my code:

function comparse($txt)
{
  $arrg = [];
  $bracks = "/\[(.*)\]/";
  if(preg_match($bracks,$txt))
  {
    preg_match_all($bracks,$txt,$matches);
    foreach($matches[1] as $match)
    {
      $spl = explode("%",$match,2);
      $arrg[$spl[0]] = comparse($spl[1]);
    }
  }else{
    $arrg = $txt;
  }
  return $arrg;
}

print_r(comparse($str));

Simple script of iterating character by character and when it finds the opening tag, it starts recording the text inside, and even records recursive opening and closing brackets and doesn't parse them as of yet the code being half done. Here is the code as it is being updated:

http://js.x10.bz/projects/recursive/recursive.txt

Here it is in action as I develop it for recursion:

http://js.x10.bz/projects/recursive/recursive.php

Edit, Finished

Code is fnished, works as follows:

single value: [a:a]
recursive value: [a:[a:a]]
array value: [a:[a:1][b:2]]

$str = "[a:[a:1][b:2]]";
$arr = fromnest($str,"[/./:/./]"); // /./ is the separator marking opening, value indicator and closing brackets
print_r($arr);

Output:
Array(
  "a" => array(
    "a" => 1,
    "b" => 2
  )
)

Which is the intended output.