jonneve has asked for the wisdom of the Perl Monks concerning the following question:
where $braces was defined as :s/class \s+ (?<class_name> \w+) \s* (\: (\s* \w*)? \s* (?<ancestor> \w+))? \s* $braces //x
It matched correctly if I simplified it to the following:$braces = qr/(?<braces>\{ ([^\{\}] | (?&braces))*? \} )/x;
That wasn't acceptable however, because by removing the recursion, I was no longer able to match the braces correctly and it therefore failed if there were two sets of braces following each other (it greedily matched right up to the last closing brace. So basically, my question is what the limitations are that caused this problem. I realize that I'm pushing things to the limit and that at this point, it's probably better, just from a performance point of view, to split things up into smaller expressions by doing a bit of basic parsing by hand first (that's what I ended up doing, and it works fine). I did waste a good 2 hours trying to figure out why the regex wasn't working though, so I'd kind of like to know for next time what the limitations are... Thanks in advance, Jonathans/class \s+ (?<class_name> \w+) \s* (\: (\s* \w*)? \s* (?<ancestor> \w+))? \s* \{ (?<class_body> [\s\S]+ ) \} \s*; //xm
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl regex limitations (32k)
by tye (Sage) on Aug 06, 2014 at 00:36 UTC | |
by tye (Sage) on Aug 06, 2014 at 04:13 UTC | |
by oiskuu (Hermit) on Aug 06, 2014 at 12:21 UTC | |
by jonneve (Initiate) on Aug 06, 2014 at 13:20 UTC | |
by jonneve (Initiate) on Aug 06, 2014 at 14:03 UTC | |
by Anonymous Monk on Aug 06, 2014 at 16:08 UTC | |
|
Re: Perl regex limitations
by Laurent_R (Canon) on Aug 05, 2014 at 20:54 UTC | |
|
Re: Perl regex limitations
by oiskuu (Hermit) on Aug 05, 2014 at 22:39 UTC | |
|
Re: Perl regex limitations (m/\G.../gc)
by tye (Sage) on Aug 06, 2014 at 16:03 UTC | |
by AppleFritter (Vicar) on Aug 06, 2014 at 17:03 UTC |