+ return pos($_[0]) ? $new . substr($_[0], pos $_[0]) : $_[0];
+}
+
+### use a regular expression to go through the string bruteforce
+sub parse_pos_array {
+ my $new = '';
+ my $START = '[%';
+ my $END = '%]';
+
+ local pos($_[0]) = 0;
+ my @start1;
+ my @start2;
+ while ($_[0] =~ /(\Q$START\E)/g) { push @start1, $-[1]; push @start2, $+[1] }
+
+ local pos($_[0]) = 0;
+ my @end1;
+ my @end2;
+ while ($_[0] =~ /(\Q$END\E)/g) { push @end1, $-[1]; push @end2, $+[1] }
+
+ my $last = 0;
+ while (1) {
+ last if ! @start1;
+ my $i = shift @start1;
+ my $i2 = shift @start2;
+
+ $new .= substr($_[0], $last, $i - $last);
+
+ die "Unclosed tag" if ! @end1;
+ my $j = shift @end1;
+ my $j2 = shift @end2;
+
+ my $tag = substr($_[0], $i2, $j - $i2);
+ $new.= "($tag)";
+
+ $last = $j2;
+ }
+ return $last ? $new . substr($_[0], $last) : $_[0];