good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Count capturing parentheses in a compiled regexpby hv (Prior) |
on May 02, 2004 at 12:12 UTC ( [id://349802]=note: print w/replies, xml ) | Need Help?? |
Nice snippet, but a couple of problems: the outer lookahead needs to be //s, else eg: will fail. Also, this will find parens in embedded code and comments and treat as captures. If that doesn't seem worth worrying about it'd be enough to add a caveat I guess, else I think you can mimic perl's simplistic parsing reasonable easily for the code (just count to the balancing close-brace). Comments may actually be the trickiest, since you'll need to know when //x is in force:
Oops, another one: parens in [ ... ] should be ignored too; I'm not sure how easy those would be to parse, since not every ] closes the selection. Hugo
In Section
Cool Uses for Perl
|
|