#!/usr/bin/perl # http://perlmonks.org/?node_id=1203332 use strict; use warnings; my @test = ("ananas", "de:mindset:rule1", "en:mindset:rule1", "wiki:we +lcome", " de:sidebar", "sidebar", "en:sidebar", "start", "de:start", "en:start") +; my ($cnt, $result); print "start first loop <var !=> \n"; $cnt=0; foreach (@test) { if ($_ !~ /(start|sidebar)/) { print " >$_<\n"; $cnt++; } } $result = ($cnt eq 4? ">> correct result" : ">> wrong result"); print "end first loop <$cnt> is $result\n\nstart second loop <negative + lookahea d>\n"; $cnt=0; foreach (@test) { if ($_ =~ /^(?!.*start|.*sidebar)/s) { print " >$_<\n"; $cnt++; } } $result = ($cnt eq 4? ">> correct result" : ">> wrong result"); print "end second loop <$cnt> is $result\n"; print ">>pgm ended\n";
In reply to Re: regex negativ lookahead
by tybalt89
in thread regex negativ lookahead
by SwissGeorge
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |