Forum: CFEngine Help
Subject: problem with negative lookahead regex
Author: svenXY
Link to topic: https://cfengine.com/forum/read.php?3,24188,24188#msg-24188
Hi,
I'm debugging a regex problem here (with 3.2.0)
Without any replace action or so, I first want to make sure my regexes work as
expected.
What I want is find out if a line starts with "log4j.rootLogger=", then
something else, then does not contain the string ", SYSLOG". This works fine
when specifying the whole string, but as soon as I use '(.*)' or even '(.*?)'
inbetween, the regex fails.
Here's some code to demonstrate:
body common control
{
bundlesequence => { "test" };
}
bundle agent test
{
vars:
"start" string => "log4j.rootLogger=";
"startlong" string => "log4j.rootLogger=INFO, FILE";
"end" string => ", SYSLOG";
classes:
"matched_origin" expression => regcmp("^($(start)(.*?))(?!$(end))$",
"log4j.rootLogger=INFO, FILE");
"matched_whole" expression => regcmp("^($(start)(.*?))(?!$(end))$",
"log4j.rootLogger=INFO, FILE, SYSLOG");
"matched_l_origin" expression => regcmp("^($(startlong))(?!$(end))$",
"log4j.rootLogger=INFO, FILE");
"matched_l_whole" expression => regcmp("^($(startlong))(?!$(end))$",
"log4j.rootLogger=INFO, FILE, SYSLOG");
reports:
matched_origin::
"this should match - start is not followed by end";
matched_whole::
"this should not match (best version)";
matched_l_origin::
"should match, but start contains the whole string";
matched_l_whole::
"this should not match (whole string version)";
}
output is:
R: this should match - start is not followed by end
R: this should not match (best version)
R: should match, but start contains the whole string
- the second one is my problem. It should not work, because I do the following
there:
"log4j.rootLogger=INFO, FILE, SYSLOG" matched against
"^(log4j.rootLogger=(.*?)(?!, SYSLOG)$"
--> and that should not match!!!
Is that a bug or can someone enlighten my poor understanding of regexes here?
Thaanks a bunch,
Sven
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine