Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Negating Regexes: Tips, Tools, And Tricks Of The Trade

by Sartak (Hermit)
on Dec 09, 2006 at 02:08 UTC ( #588749=note: print w/ replies, xml ) Need Help??


in reply to Negating Regexes: Tips, Tools, And Tricks Of The Trade

It's interesting that you ask this now. Just yesterday I was developing an IRC bot and a question like this came up; basically, how to write the negation of a regex.

The way I solved it was to add a new flag (not to Perl, but to the regex the users write), /r, that negates the return value of the match. So a user can do !grep /^ascended$/r to match all entries that don't match exactly "ascension". I haven't run into any major problems yet. :) I only match in boolean context (and without using any capturing variables).. I don't know if it'd work so well if I needed to do anything more complicated.


Comment on Re: Negating Regexes: Tips, Tools, And Tricks Of The Trade
Select or Download Code
Re^2: Negating Regexes: Tips, Tools, And Tricks Of The Trade
by ikegami (Pope) on Dec 09, 2006 at 05:53 UTC

    How's grep /^ascended$/r different from grep !/^ascended$/?

    Update: Nevermind, I understand. The user submits /^ascended$/r, which you transform to !/^ascended$/ to execute. I thought you had patched Perl :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-07-13 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (250 votes), past polls