[Freeswitch-users] LUA pattern match question

Sean Devoy sdevoy at bizfocused.com
Fri Jul 18 20:10:26 MSD 2014


Hi All,

I have modified this excellent example LUA script (https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example) 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!

My request is for someone to explain the pattern matching pattern used in this function:
    function trim (s)
       return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
    end

It takes a string like this:
"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
d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/4107673000 at 66.241.96.237,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,,fs_bfis.bizfocused.com,4107673000 at 66.241.96.237,,ACTIVE,,,,,,

1 total."

or just this:
"
0 total."

And returns just the number and the "Total." at the end, like "1 total." Or "0 total."

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.

Thanks as always,
Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20140718/bcb4647e/attachment-0001.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list