Balanced brackets: Difference between revisions
Content added Content deleted
VincentARM (talk | contribs) (Add task to aarch64 assembly raspberry pi) |
SqrtNegInf (talk | contribs) 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 ( |
<code>Regexp::Common::balanced</code> can give such a regexp too (here via a subroutine call) |
||
<syntaxhighlight lang="perl">use Regexp::Common ' |
<syntaxhighlight lang="perl">use Regexp::Common 'RE_balanced'; |
||
my $re = qr/^$RE{balanced}{-parens=>'[]'}$/; |
|||
sub balanced { |
sub balanced { |
||
return shift =~ |
return shift =~ RE_balanced(-parens=>'[]') |
||
} |
|||
</syntaxhighlight> |
|||
Alternative implementation, using straightforward depth counting: |
Alternative implementation, using straightforward depth counting: |