Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Perl regex limitations

by oiskuu (Hermit)
on Aug 05, 2014 at 22:39 UTC ( #1096366=note: print w/replies, xml ) Need Help??

in reply to Perl regex limitations

With complicated regular expressions like that, limiting the amount of back-tracking becomes an important concern. This may be addressed with possessive quantifiers: (?>...), *+, etc. Consider the following version:

use warnings; $braces = qr/(?<braces> { (?: [^{}] | (?&braces) )*+ } )/x; s/class \s+ (?<class_name> \w+) \s* (\: (\s* \w*)? \s* (?<ancestor> \w+))?+ \s* $braces //x;
Note the possessive *+ and ?+. But this probably does not solve your problem. Are you sure the braces were properly balanced in your input? Could there have been some escaped or quoted brace(s) that failed to match up?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096366]
and not a whimper to be heard...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2017-06-28 21:42 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (649 votes). Check out past polls.