Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2016-10-28 03:28 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (374 votes). Check out past polls.