Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: regex substring negation

by johngg (Abbot)
on Jul 02, 2007 at 09:27 UTC ( #624403=note: print w/replies, xml ) Need Help??


in reply to regex substring negation

If you mean that you only want the match to succeed if a string doesn't contain a substring you could use a negative look-ahead.

my $string = q{the quick black fox}; my $substring = q{brown}; if ( $string =~ m{\A(?!.*\Q$substring\E).*fox} ) { print qq{Found a non-$substring fox\n}; } else { print qq{Match failed, $substring seen\n}; }

I hope this is of use.

Cheers,

JohnGG

Update: Typo, s/negatine/negative/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://624403]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-10-20 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (263 votes). Check out past polls.

    Notices?