in reply to Re: Regex conditional match if previous match in same expression is true?
in thread Regex conditional match if previous match in same expression is true?
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 }) } | (?!}) )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex conditional match if previous match in same expression is true?
by demerphq (Chancellor) on Apr 10, 2007 at 17:30 UTC | |
by ikegami (Patriarch) on Apr 10, 2007 at 17:37 UTC |