It doesn't deal with escaped or quoted parens -- i.e. they are treated like any other. It doesn't deal with nulls in the input very well, to make it do that would cost 3 extra chars. It doesn't let you know where you're unbalanced, but simply prints `1' if the input is balanced and prints nothing if it's not. Oh, and it requires 5.6.0 or better.
Give it a filename to check for balancing on the command line, or run it as shown below exactly and give it text to check on standard input.
-dlc
perl -n0e'$r=qr/(?>[^()]*)|\((??{$r})+\)/;print/^$r*$/'
In reply to Match nested parens of arbitrary depth in 56 characters by dchetlin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |