<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12px"><div id="yui_3_16_0_1_1436938466343_12037">Hello!</div><div id="yui_3_16_0_1_1436938466343_12118"><br></div><div id="yui_3_16_0_1_1436938466343_12158" dir="ltr">I run a varnish installation and I encountered an odd behaviour when trying to get a cookie and its value using regsub(); here is the code:</div><div id="yui_3_16_0_1_1436938466343_12264" dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12263" dir="ltr">vcl_hash() {</div><div id="yui_3_16_0_1_1436938466343_12197" dir="ltr">[...]</div><div id="yui_3_16_0_1_1436938466343_12196" dir="ltr">hash_data(regsub(req.http.cookie,"(LoggedIn=[^;]+;)","\1"));</div><div id="yui_3_16_0_1_1436938466343_12208" dir="ltr">[...]</div><div id="yui_3_16_0_1_1436938466343_12265" dir="ltr">return(hash)<br></div><div id="yui_3_16_0_1_1436938466343_12195" dir="ltr">}</div><div id="yui_3_16_0_1_1436938466343_12603" dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12237" dir="ltr">The LoggedIn cookie takes integer values depending on the user type and there are multiple user types (or groups).</div><div id="yui_3_16_0_1_1436938466343_12367" dir="ltr">The regex should match only the cookie name, followed by the equal sign, followed by the user type value and finally followed by semicolon and then return the matched string.</div><div id="yui_3_16_0_1_1436938466343_12397" dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12396" dir="ltr">What varnish does instead is it returns an arbirarily truncated cookie:</div><div id="yui_3_16_0_1_1436938466343_12398" dir="ltr">56 Hash c ASP.NET_SessionId=piejvbp31o4cbdsbzak55j2c; LoggedIn=0; __utma=203440913.1436939550.; __utmb=203440913.; __utmc=20913; __utmz=203440913..utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)</div><div id="yui_3_16_0_1_1436938466343_12577" dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12576" dir="ltr">(Note: I manually truncated/edited __utm* cookies' values intentionally.)</div><div id="yui_3_16_0_1_1436938466343_12575" dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12574" dir="ltr">What am I doing wrong, or what should I know more about regsub() to be able to return the intended string?</div><div id="yui_3_16_0_1_1436938466343_12573" dir="ltr">I tested the regex on regex101.com and it works correctly there.</div><div id="yui_3_16_0_1_1436938466343_12572" dir="ltr"><br></div><div id="yui_3_16_0_1_1436938466343_12571" dir="ltr">Thank you for your help!</div><div id="yui_3_16_0_1_1436938466343_12566" dir="ltr">Sorin.<br></div></div></body></html>