<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
  Hello,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
You need double escaping:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
With this version, it worked for me:<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Consolas, Courier, monospace;">    rewrite { subst("^.+\\((.+)\\)", "${1}", value("user_name")) ;};</span><span><br>
</span><span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Br,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
  Antal<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> syslog-ng <syslog-ng-bounces@lists.balabit.hu> on behalf of Russell Fulton <r.fulton@auckland.ac.nz><br>
<b>Sent:</b> Sunday, April 12, 2020 23:03<br>
<b>To:</b> Syslog-ng users' and developers' mailing list <syslog-ng@lists.balabit.hu><br>
<b>Subject:</b> [syslog-ng] issues with rewrite and subst</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">
<div style="background-color:#FFEB9C; width:100%; border-style:solid; border-color:#9C6500; border-width:1pt; padding:2pt; font-size:10pt; line-height:12pt; font-family:'Calibri'; color:Black; text-align:left">
<span style="color:#9C6500; font-weight:bold">CAUTION:</span> This email originated from outside of the organization. Do not follow guidance, click links, or open attachments unless you recognize the sender and know the content is safe.</div>
<br>
<div>
<div class="">version 3.26.1</div>
<div class=""><br class="">
</div>
I am attempting to use rewrite to copy part of one macro into a new one:
<div class=""><br class="">
</div>
<div class=""><font face="Menlo" class="">rewrite r_user1 { set( "${user}", value("user_name"));};<br class="">
rewrite r_user2 { subst( "^.+\((.+)\)", "${1}", value("user_name")) ;};<br class="">
</font><br class="">
</div>
<div class="">The first simply copies <font face="Menlo" class="">user</font> into
<font face="Menlo" class="">user_name.</font></div>
<div class="">The second is intended to extract anything in parentheses and throw away the rest.</div>
<div class=""><br class="">
</div>
<div class="">here is a cleaned up dump of json output including the macros from the regexp:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal; font-family:Menlo">
<span class="" style="font-variant-ligatures:no-common-ligatures">{"user_name":")","user”:”yyyyn@gmail</span><span class="" style="font-variant-ligatures:no-common-ligatures">.com(xxx549)"</span><span class="" style="font-variant-ligatures:no-common-ligatures">,"2":")","1":")","0”:”yyyy@<span class="" style="">gmail</span></span><span class="" style="font-variant-ligatures:no-common-ligatures">.com(xxx549)”}</span></div>
</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal; font-family:Menlo">
<span class="" style="font-variant-ligatures:no-common-ligatures"><br class="">
</span></div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal">
I believe ‘1’ should contain ‘xxx549’ not ‘)’.</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal; font-family:Menlo">
<br class="">
</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal">
I have tested the regexpn in ruby’s irb and it works fine there.</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal">
<br class="">
</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal">
here is another example this one where the regexp should not have matched at all:</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal">
<br class="">
</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal">
<div class="" style="margin:0px; font-stretch:normal; line-height:normal; font-family:Menlo">
<span class="" style="font-variant-ligatures:no-common-ligatures">{"user_name":"9","user":"ping999","2":"9","1":"9","0":"ping999”}</span></div>
<div class="" style="margin:0px; font-stretch:normal; line-height:normal; font-family:Menlo">
<span class="" style="font-variant-ligatures:no-common-ligatures"><br class="">
</span></div>
<div class="" style="margin:0px; font-stretch:normal; line-height:normal"><span class="" style="font-variant-ligatures:no-common-ligatures">macros 1 and 2 always seem to contain the last character of the original string.</span></div>
<div class="" style="margin:0px; font-stretch:normal; line-height:normal"><span class="" style="font-variant-ligatures:no-common-ligatures"><br class="">
</span></div>
<div class=""><span class="" style="font-variant-ligatures:no-common-ligatures"><br class="">
</span></div>
</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal; font-family:Menlo">
<br class="">
</div>
<div class="" style="margin:0px; font-stretch:normal; font-size:11px; line-height:normal; font-family:Menlo">
<br class="">
</div>
</div>
</div>
</body>
</html>