in reply to Re: regex negativ lookahead
in thread regex negativ lookahead
well why not using !~ ? because it's a configuration value, accepting regexp and a do know the pattern for excluding values from a array. my "real problem script" does work with real data.
by now i first try to understand perl functions .. perlref Lookaround Assertions as you already noted. first of all any tests with positiv lookahaed ($var =~ /a(?=string)/) work as expected.
negativ lookahead did not work as expected. let's focus on:
("gugus" =~ /gu(?!gu)/) ==> <gugus> found ("gu", "gu", "s")
and
("gugis" =~ /gu(?!gi)/) ==> <gugis> nomatch (undef, undef, undef)
do not solve the same. was using your proposal to dump match array. great idea, thank you
and now i'm about to transfer this problem into Test::More.use strict; use warnings; use Data::Dump; my @var1 = ('gugu', 'gugus', 'and gugut for','gugas and', 'gurit for', +'granit') ; my @var2 = ('gugi', 'gugis', 'and gugit for','gugas and', 'gurit for', +'granit') ; my ($ret, $match); print ("get any string 'gu' not followed by 'gu'\n"); foreach (@var1) { $ret = $_ =~ /gu(?!gu)/p; $match = $ret eq 1 ? 'found' : 'nomatch'; print "<$_> $match "; dd ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH}; } print ("\nget any string 'gu' followed by 'gi'\n"); foreach (@var2) { $ret = $_ =~ /gu(?!gi)/p; $match = $ret eq 1 ? 'found' : 'nomatch'; print "<$_> $match "; dd ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: regex negativ lookahead
by haukex (Archbishop) on Nov 14, 2017 at 15:43 UTC |