That doesn't give me the desired results at all. I was using Perl 5.6, but $^N was only introduced in 5.8.
By the way, you should localize your package variables whenever possible. Replace
our $paren;
with
local our $paren;
I'd also add a comment along the lines of "Always use package variables with regular expressions." Someone reading or maintaining the code could very well not know that lexical variables can cause problems.
Finally, to avoid continually compiling regexp fragments, replace
(??{$paren ? "\}" : "(?!\})"})
with
(?(?{ $paren }) } | (?!}) )
In reply to Re^2: Regex conditional match if previous match in same expression is true?
by ikegami
in thread Regex conditional match if previous match in same expression is true?
by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |