in reply to Re: Is there a hard limit on + in a regex?
in thread Is there a hard limit on + in a regex?

Same for me. It's the equivalent construct inside XML::Validator::Schema which isn't working past 32,768 iterations.

-sam

  • Comment on Re^2: Is there a hard limit on + in a regex?

Replies are listed 'Best First'.
Re^3: Is there a hard limit on + in a regex?
by Joost (Canon) on Jul 09, 2004 at 20:09 UTC
    Can you give a bit of working code (edit: I mean, code that give that error) that demonstrates the problem (using XML::Validator::Schema if you have to)?

    As noted here, there are limits, but maybe you can work around it.

    Also, these paragraphs in http://search.cpan.org/src/NWCLARK/perl-5.8.4/hints/machten.sh claim that you can compile perl with higher limits on regex repeats, irrespective of the architecture defaults:

    # Set reg_infty -- the maximum allowable number of repeats in regular # expressions such as /a{1,$max_repeats}/, and the maximum number of # times /a*/ will match. Setting this too high without having a stack # large enough to accommodate deep recursion in the regular expression # engine allows perl to crash your Mac due to stack overrun if it # encounters a pathological regular expression. The default is a # compromise between capability and required stack size (see below). # You may override the default value from the Configure command-line # like this: # # Configure -Dreg_infty=16368 ... reg_infty=${reg_infty:-2047} # If you want to have many perl processes active simultaneously -- # processing CGI forms -- for example, you should opt for a small stac +k. # For safety, you should set reg_infty no larger than the correspondin +g # value given in this table: # # Stack size reg_infty value supported # ---------- ------------------------- # 128k 2**8-1 (256) # 256k 2**9-1 (511) # 512k 2**10-1 (1023) # 1M 2**11-1 (2047) # ... # 16M 2**15-1 (32767) (perl's default value) # This script selects a safe stack size based on the value of reg_inft +y # specified above. However, you may choose to take a risk and set # stack size lower: pathological regular expressions are rare in real- +world # programs. But be aware that, if perl does encounter one, it WILL # crash your system. Do not set stack size lower than 96k unless # you want perl's installation tests ( make test ) to crash your syste +m. # # You may override the default value from the Configure command-line # by specifying the required size in kilobytes like this: # # Configure -Dstack_size=96
      Can you give a bit of working code (edit: I mean, code that give that error) that demonstrates the problem (using XML::Validator::Schema if you have to)?

      That would be hard, and probably useless. I'm pretty well convinced that there are hard limits on the regex repetition operators which I can't avoid. Even if you can recompile Perl to make them bigger, that doesn't mean they'll ever go away. I guess I'll just document the limitation in XML::Validator::Schema and leave it at that.

      The only thing I can't figure out is why my attempts to verify that those limits exist failed.

      -sam

        Your attempts used too-simple constructs so they didn't have the limit.