You can just get the first entry in your match array like this:
$s2 = "1$^20";
preg_match_all("/(\d+)(?:\$\^){0,1}/", $s2, $n);
print_r($n[0]);
// Array ( [0] => 1 [1] => 20 )
Or drop the group and just extract the numbers like this:
$s2 = "1$^20";
preg_match_all("/\d+/", $s2, $n);
print_r($n);
// Array ( [0] => Array ( [0] => 1 [1] => 20 ) )
Another alternative might be to use preg_split
:
$s2 = "1$^20";
$n = preg_split('/\$\^/', $s2);
print_r($n);
// Array ( [0] => 1 [1] => 20 )