Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perl regex limitations

by oiskuu (Friar)
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?


Comment on Re: Perl regex limitations
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2015-03-05 21:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:









    Results (153 votes), past polls