Forum: CFEngine Help Subject: SOLVED: problem with negative lookahead regex Author: svenXY Link to topic: https://cfengine.com/forum/read.php?3,24188,24208#msg-24208
Hi, thanks for all the suggestions. I guess it was a misconception or missing insight into PCRE. I have it working now. What I needed was the ability to: 1) check if the line already ended with ", SYSLOG" 2) if not, capture the whole line 3) append ", SYSLOG" 4) The developers wanted to remain flexible with whatever was between "rootLoggger=" and ", SYSLOG" Here_'s what I have come up with: bundle edit_line syslog_appender(app_name) { vars: "start" string => "log4j.rootLogger="; "end" string => ", SYSLOG"; replace_patterns: "^(${start}(\w+(,\s)?)+)(?<!${end})$" replace_with => value("$(match.1)$(end)"), comment => "Append syslog appender"; insert_lines: "log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender"; "log4j.appender.SYSLOG.syslogHost=127.0.0.1"; "log4j.appender.SYSLOG.facility=LOCAL0"; "log4j.appender.SYSLOG.layout=de.denic.techsupport.log.MultiLinePatternLayout"; "log4j.appender.SYSLOG.layout.ConversionPattern=$(app_name): %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%x] %-5p %m%n"; "log4j.appender.SYSLOG.threshold=INFO" comment => "Append lines to the file if they don't already exist"; } Cheers, Sven _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine