in reply to Re: Perl regex limitations (32k)
in thread Perl regex limitations

Warnings enabled, the 32k problem should have manifested itself:

Complex regular subexpression recursion limit (32766) exceeded
To work around this problem (a warning remains), one may double the repeat quantifiers, e.g.:
my $braces = qr/(?<braces> { (?: (?: [^{}] | (?&braces) )*+ )* } )/x;

perlre has the following example on handling nested parens:

my $parens = qr/(\((?:[^()]++|(?-1))*+\))/; if (/foo $parens \s+ \+ \s+ bar $parens/x) { # do something here... }

Replies are listed 'Best First'.
Re^3: Perl regex limitations (32k)
by jonneve (Initiate) on Aug 06, 2014 at 13:20 UTC
    Thanks for all the replies! I tried adding the following test to see if I can get it working (as I said, I have now rewritten it to do the parsing by hand, but I would like to figure it out for next time):
    $braces = qr/(?<braces>\{ ([^\{\}]++ | (?&braces))*+ \} )/x; if ($h =~ s/class \s+ (?<class_name> \w+) \s* (\: (\s* \w*)? \s* (?<an +cestor> \w+))? \s* $braces//x) { print "hi\n"; }
    The match is never made however... The code I'm matching against is a C++ header file, and I'm looking for class definitions, formatted like this :
    class MyClassName : public MyAncestorClass { ... ... };
    This expression works fine for smaller classes or for this same problem class if there are no braces inside the class definition. In this class however, I have the following declarations (C++ Builder code...) :
    __property TNotifyEvent OnMonaDocSaveToDB = {read=FOnMonaDocSaveToDB +, write=FOnMonaDocSaveToDB};
    If I remove that property declaration, it matches, if I leave it, it fails... Jonathan
Re^3: Perl regex limitations (32k)
by jonneve (Initiate) on Aug 06, 2014 at 14:03 UTC
    I just checked, there is no warning when I execute my script using "perl -w"...

      On the off chance that you've stumbled upon an undiscovered bug, the considerate route to take is to provide a testcase. This may involve some tedious work reducing a self-contained test unit to a minimum. That, of course, after you've verified the behavior with the latest perl.