in reply to Regex code assertion should be able to fail

Some time ago I figured out how to combine the succeed/fail operator and the execute-code operator. This includes the use of (?!) to force a failure. I think this is what you need, if I understood your question. It was not at all obvious to me, so I wrote it up here before.

combining (?(condition)yes|no) and (?{code})

Does this help?

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: Regex code assertion should be able to fail
by nobull (Friar) on Sep 06, 2007 at 17:22 UTC
    Unless I'm missing something, the technique you describe is essentially the one I described in my original post as the technique I'd use in 5.8 (and was hoping for something more concise).

    /(?(?{ whatever() })|(?!))/

    Did I miss something?

    Update: halley replied via /msg. His post was describing the same technique but gives more details for the benefit of on-lookers.

    To clarify how I see this being used here's the code example from my patch to perlre:

    @known_animal{ qw( cat dog fox horse rabbit rat ) } = (); @animals = /\b(\w++)(?{ exists $known_animal{$^N} }?)/g; print "@animals\n";