<div dir="ltr"><span style="color:rgb(51,51,51);font-family:&#39;Courier New&#39;;font-size:13px;line-height:20px">&quot;^%s*(.-)%s*$&quot;, &quot;%1&quot;</span><br><div><br></div><div>Lua uses it&#39;s own regex syntax, which is different from others you might be used to (eg PCRE). Though there&#39;s a few similarities.</div>

<div><br></div><div>Match start of line, 0+ space, 0+ any character (as few times as possible, so it doesn&#39;t include any trailing spaces), 0+ space, end of string</div><div>When matched replace the string with the matched portion.</div>

<div><br></div><div>It&#39;ll match any string.</div><div><br></div><div>It replaces it with the middle portion that excludes the leading/trailing spaces.</div><div><br></div><div>In this case I assume ^$ are matching the start/end of lines not strings, and matching just the final line so you&#39;re only left with the &#39;0 Total&#39;</div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 18 July 2014 17:10, Sean Devoy <span dir="ltr">&lt;<a href="mailto:sdevoy@bizfocused.com" target="_blank">sdevoy@bizfocused.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal">Hi All,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I have modified this excellent example LUA script (<a href="https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example" target="_blank">https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example</a>) to return “true” if an
 extension is in use and “false” otherwise”.  Just FYI: this is great for Cisco phones because an auto-answer (intercom) connection will interrupt the current call unless you block ALL intercom use.  With this I can sent intercom if not in use, or send as a
 standard call otherwise.  My complements to the original chef!<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">My request is for someone to explain the pattern matching pattern used in this function:<u></u><u></u></p>
<p class="MsoNormal" style="line-height:15.0pt"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#333333">    function trim (s)</span><span style="font-size:10.5pt;font-family:Consolas;color:#333333"><u></u><u></u></span></p>


<p class="MsoNormal" style="line-height:15.0pt"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#333333">       return (string.gsub(s, &quot;^%s*(.-)%s*$&quot;, &quot;%1&quot;))</span><span style="font-size:10.5pt;font-family:Consolas;color:#333333"><u></u><u></u></span></p>


<p class="MsoNormal" style="line-height:15.0pt"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#333333">    end</span><span style="font-size:10.5pt;font-family:Consolas;color:#333333"><u></u><u></u></span></p>


<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">It takes a string like this:<u></u><u></u></p>
<p class="MsoNormal">“uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,sent_callee_name,sent_callee_num<u></u><u></u></p>


<p class="MsoNormal">d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/<a href="mailto:4107673000@66.241.96.237" target="_blank">4107673000@66.241.96.237</a>,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,,<a href="http://fs_bfis.bizfocused.com" target="_blank">fs_bfis.bizfocused.com</a>,<a href="mailto:4107673000@66.241.96.237" target="_blank">4107673000@66.241.96.237</a>,,ACTIVE,,,,,,<u></u><u></u></p>


<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">1 total.”<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">or just this:<u></u><u></u></p>
<p class="MsoNormal">“<u></u><u></u></p>
<p class="MsoNormal">0 total.”<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">And returns just the number and the “Total.” at the end, like “1 total.” Or “0 total.”<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am fairly regex pattern savvy so I understand pattern matching, but I cannot decipher this LUA pattern.  I see it works, but I would like to understand how/why.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks as always,<u></u><u></u></p>
<p class="MsoNormal">Sean <u></u><u></u></p>
</div>
</div>

<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br></div>