Sunday, January 2, 2011

Perl: Negating the regex

Negating the regex

If you want to negate the entire regex change =~ to !~ (Remember ! means 'not equal to'.)
if ($_ !~/[KC]arl/) {
Of course, as we are testing $_    
this works too: 
if (!/[KC]arl/) {
....
}

No comments: