[Freeswitch-users] LUA pattern match question
Steven Ayre
steveayre at gmail.com
Sun Jul 20 00:47:17 MSD 2014
"^%s*(.-)%s*$", "%1"
Lua uses it's own regex syntax, which is different from others you might be
used to (eg PCRE). Though there's a few similarities.
Match start of line, 0+ space, 0+ any character (as few times as possible,
so it doesn't include any trailing spaces), 0+ space, end of string
When matched replace the string with the matched portion.
It'll match any string.
It replaces it with the middle portion that excludes the leading/trailing
spaces.
In this case I assume ^$ are matching the start/end of lines not strings,
and matching just the final line so you're only left with the '0 Total'
On 18 July 2014 17:10, Sean Devoy <sdevoy at bizfocused.com> wrote:
> 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
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
>
>
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20140719/2e07d6d0/attachment.html
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list