Forum: CFEngine Help Subject: Re: problem with negative lookahead regex Author: sauer Link to topic: https://cfengine.com/forum/read.php?3,24188,24196#msg-24196
So, you have a comma-delimited string, and you don't want SYSLOG to be one of those comma-delimited elements? Or is it OK if SYSLOG is the first element? If you actually want to make sure that no element in that comma+whitespace delimited string isn't SYSLOG (including the first one), you'll want something more like "one or more patterns after the equal sign which are non-comma characters followed by either a comma and one or more whitespace, or 0 or more whitespace and then the end of the line, with the additional qualification that the non-comma string cannot be 'SYSLOG followed by either a comma or optional whitespace and the end of the line'." I'd therefore go with something more like this: log4j\.rootLogger=((?!SYSLOG(,|\s*\Z))[^,]+(,\s+|\s*\Z))+\Z But then you should probably stick some ?: combos in front of the parenthetical matches which you don't want to preserve for later (and parens around the whole thing for actual matching purposes), so you actually end up with this: ($(start)(?:(?!SYSLOG(?:,|\s*\Z))[^,]+(?:,\s+|\s*\Z))+)\Z The \Z being zero-width EOL matching basically means you can safely use it multiple times. :) _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine