Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: positive regex for inverted match

by kvale (Monsignor)
on Feb 26, 2004 at 06:33 UTC ( [id://331921]=note: print w/replies, xml ) Need Help??


in reply to positive regex for inverted match

Here is a regex solution to you problem:
while (<DATA>) { chomp; print "$_ has no bar\n" if /^([^b]|b[^a]|ba[^r])+$/; } __DATA__ bar foo "bar" blah baz "bar" blah "test" blah "test2"

-Mark

Replies are listed 'Best First'.
Re^2: positive regex for inverted match (classic)
by tye (Sage) on Feb 26, 2004 at 07:55 UTC

    Classic++, including classic mistakes. (:

    Your regex will match "bbar" despite it containing "bar". "bb" matches b[^a] and then "a" and "r" each match [^b].

    I started exploring this idea in depth and hope to write a lengthy node on it one day. Trying to fix the problems leads you down paths similar to:

    /^([^b]|b[^a]| ba[^r])+$/ /^([^b]+|b+[^ab]| b+a[^rb])*b*a?$/ /^([^b]+|b+[^ab]|(b+a)+([^rb]|b+[^ab]))*[ba]*$/

    - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found