Perl regular expressions – limit

Just ran into a limitation of Perl regular expressions. It’s mentioned (in brackets!) here: http://www.foo.be/docs/tpj/issues/vol1_2/tpj0102-0006.html, but I didn’t see mention of it in the Perl manual, so this wasn’t easy to track down.

It’s stated as: “Perl currently has an internal limit of 32K repeats for parenthetical items”. The following code is sufficient to demonstrate the limitation, which seems to apply specifically to the case of a repeated parenthetical item with a pipe separator ((?:.|.)*):

foreach ( 32000, 33000 )
{
  my $data = sprintf ( "%${_}s" );
  my ( $sub ) = ( $data =~ /^((?:.|.)*)$/ );
  print "data=" . length ( $data ) . "; sub=" . length ( $sub ) . "\n";
}

Leave a Reply

Your email address will not be published. Required fields are marked *