P
Paul Kaletta
Hi,
I think I don't understand something about negative lookahead in
regular expressions.
This program
if ($string =~ /-+(?!foo)/) {
print "Does match!\n";
} else {
print "Doesn't match!\n";
}
reports that $string = "-foo" doesn't match. That's what I expected.
But why does $string = "--foo" match? It seems to me that negative
look-ahead doesn't work after a quantifier like "+".
Of course
"--foo" =~ /-+(.*)/;
print $1;
prints "foo". I figured that by just replacing (.*) with (?!foo) I
could create a regex that doesn't match "--foo". I simply can not
figure it out.
Thanks,
Paul
I think I don't understand something about negative lookahead in
regular expressions.
This program
if ($string =~ /-+(?!foo)/) {
print "Does match!\n";
} else {
print "Doesn't match!\n";
}
reports that $string = "-foo" doesn't match. That's what I expected.
But why does $string = "--foo" match? It seems to me that negative
look-ahead doesn't work after a quantifier like "+".
Of course
"--foo" =~ /-+(.*)/;
print $1;
prints "foo". I figured that by just replacing (.*) with (?!foo) I
could create a regex that doesn't match "--foo". I simply can not
figure it out.
Thanks,
Paul