Balanced brackets: Difference between revisions

Content added Content deleted
(Add task to aarch64 assembly raspberry pi)
m (→‎{{header|Perl}}: use Regexp::Common subroutine interface, works with recent versions of Perl)
Line 5,897: Line 5,897:
}</syntaxhighlight>
}</syntaxhighlight>


<code>Regexp::Common::balanced</code> can give such a regexp too (non-bracket chars allowed). Its recent versions use the subpattern recursion and are hence also only for Perl 5.10 and up.
<code>Regexp::Common::balanced</code> can give such a regexp too (here via a subroutine call)


<syntaxhighlight lang="perl">use Regexp::Common 'balanced';
<syntaxhighlight lang="perl">use Regexp::Common 'RE_balanced';
my $re = qr/^$RE{balanced}{-parens=>'[]'}$/;
sub balanced {
sub balanced {
return shift =~ $re;
return shift =~ RE_balanced(-parens=>'[]')
}
}</syntaxhighlight>
</syntaxhighlight>


Alternative implementation, using straightforward depth counting:
Alternative implementation, using straightforward depth counting: