Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Regex code assertion should be able to fail

by halley (Prior)
on Sep 04, 2007 at 15:21 UTC ( [id://636959]=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-24 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found