To do correct paren matching, you need a machine that can count. In particular, a finite automaton cannot do this (see this proof or that proof). So a real regular expression cannot do this. However, modern Perl5 regexen can do it (though the syntax is yucky).