perlquestion
svenXY
Hi,<br>
<p>I'm confused with a negative lookahead. Here's some example code. I want it to match on $needs and to not match on $has. The examples 3 and 4 are only as a reference to a fixed string, but I basically want <code>^($start(.*?))(?!$end)$</code>. Any ideas?</p>
<code>
#!/usr/bin/perl
use strict;
use warnings;
my $start = "log4j.rootLogger=";
my $startlong = "log4j.rootLogger=INFO, FILE";
my $end = ", SYSLOG";
my $needs = 'log4j.rootLogger=INFO, FILE';
my $has = $needs . ', SYSLOG';
print "needs_matched $needs\n" if $needs =~ /^($start(\w+(,\s)?)+)(?!$end)$/;
print "has_matched $has\n" if $has =~ /^($start(\w+(,\s)?)+)(?!$end)$/;
print "needs_matched $needs\n" if $needs =~ /^(log4j.rootLogger=INFO, FILE)(?!, SYSLOG)$/;
print "has_matched $has\n" if $has =~ /^(log4j.rootLogger=INFO, FILE)(?!, SYSLOG)$/;
</code>
</readmore>
<br>
Regards,<br>
svenXY