chakram88 has asked for the wisdom of the Perl Monks concerning the following question:

Oh Enlighted Ones:

I have dutifully super-searched to no avail, and I humbly ask your guidance.

I'm not sure if this is an undocumented feature, or if there is a purpose for it. (or perhaps documented where I have been unable to locate it).

Apparently there is an upper limit of '32766' on the MAX value of the regex {MIN,MAX} quantifier. I discovered this by way of the Data::FormValidator max_length constraint.

Observe:

#!/usr/bin/perl -lw my $max = 32767; my $value = "feeefooobarrr"; my $match = ($value =~ /^(.{0,$max})$/); print $match;

produces the following error:

Quantifier in {,} bigger than 32766 in regex; marked by <-- HERE in m/^(.{ <-- HERE 0,32767})$/
Has anyone come across this upper limit before? Am I missing documentation surrounding this? Is it too obscure to worry about?

Replies are listed 'Best First'.
Re: Size Limit on {MIN,MAX} Regex Quantifier?
by FunkyMonk (Bishop) on Nov 05, 2007 at 19:55 UTC
      grrrr.

      Thank you FunkyMonk.

      I'm off to do my due penance for not carefully reading the response to perldoc perlre

      I rely too much it seems on The Camel. <sigh>

Re: Size Limit on {MIN,MAX} Regex Quantifier?
by grinder (Bishop) on Nov 05, 2007 at 21:28 UTC

    Is your regexp exceptionally intricate and detailed, and your code is a cut-down example, or are you really just trying to match anything (dot).

    If it's the latter case, then a regexp is not the right way to go about solving the problem. Better to:

    my $len = length $value; if ($len < $min or $len > $max) { panic(); } else { ok(); }

    Internally, perl keeps track of string length at all times, so calling length is a very cheap operation, whereas it is quite possible that the regexp engine has to scan through the whole string to satisfy the curly.

    • another intruder with the mooring in the heart of the Perl