Hello! How can I use regexp with LUA scripts? Yes, I found I may use api:execute('regex'....) but can't understand how to get matched strings from it. For example my re is (\d+)#(\d+) and I want to get $1 and $2 in some variables. -- Regards, Boris
I don't believe there is a way to pull multiple values back from the call to api:execute. However, Lua has native pattern matching with captures. Here are a few resources for you: FreeSWITCH book, pages 149-151 http://www.lua.org/pil/20.3.html http://www.lua.org/manual/5.1/manual.html#5.4.1 Here's a simple example that you can actually run with "luarun" if you want to do some testing: -- pattern.lua data = "1234#5678"; _,_,var1,var2 = string.find(data,"(%d+)#(%d+)"); freeswitch.consoleLog("INFO","\ndata: " .. data .. "\nvar1: " .. var1 .. "\nvar2: " .. var2 .. "\n"); Output: freeswitch@internal> luarun pattern.lua +OK 2011-04-18 08:28:49.242080 [INFO] switch_cpp.cpp:1197 data: 1234#5678 var1: 1234 var2: 5678 Have fun! -MC P.S. - I added some of this information to the wiki: http://wiki.freeswitch.org/wiki/Mod_lua#Native_Lua_Pattern_Matching On Mon, Apr 18, 2011 at 6:06 AM, Boris Kovalenko <boris@tagnet.ru> wrote:
Hello!
How can I use regexp with LUA scripts? Yes, I found I may use api:execute('regex'....) but can't understand how to get matched strings from it. For example my re is (\d+)#(\d+) and I want to get $1 and $2 in some variables.
-- Regards, Boris
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Hello! Yes, I know about LUA native patterns. Unfortunatelly I can't (or don't know how to) do something like: \d{4,6} or \d{10,}
I don't believe there is a way to pull multiple values back from the call to api:execute. However, Lua has native pattern matching with captures. Here are a few resources for you:
FreeSWITCH book, pages 149-151 http://www.lua.org/pil/20.3.html http://www.lua.org/manual/5.1/manual.html#5.4.1
Here's a simple example that you can actually run with "luarun" if you want to do some testing:
-- pattern.lua data = "1234#5678"; _,_,var1,var2 = string.find(data,"(%d+)#(%d+)"); freeswitch.consoleLog("INFO","\ndata: " .. data .. "\nvar1: " .. var1 .. "\nvar2: " .. var2 .. "\n");
Output: freeswitch@internal> luarun pattern.lua +OK
2011-04-18 08:28:49.242080 [INFO] switch_cpp.cpp:1197 data: 1234#5678 var1: 1234 var2: 5678
Have fun! -MC
P.S. - I added some of this information to the wiki: http://wiki.freeswitch.org/wiki/Mod_lua#Native_Lua_Pattern_Matching
On Mon, Apr 18, 2011 at 6:06 AM, Boris Kovalenko <boris@tagnet.ru <mailto:boris@tagnet.ru>> wrote:
Hello!
How can I use regexp with LUA scripts? Yes, I found I may use api:execute('regex'....) but can't understand how to get matched strings from it. For example my re is (\d+)#(\d+) and I want to get $1 and $2 in some variables.
-- Regards, Boris
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org <mailto:FreeSWITCH-users@lists.freeswitch.org> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Regards, Boris
On Mon, Apr 18, 2011 at 9:35 AM, Boris Kovalenko <boris@tagnet.ru> wrote:
Hello!
Yes, I know about LUA native patterns. Unfortunatelly I can't (or don't know how to) do something like: \d{4,6} or \d{10,}
\d{4,6} is "%d%d%d%d%d?%d?" \d{10,} is "%d%d%d%d%d%d%d%d%d%d+" At first glance that may seem inelegant, however, it is far more efficient than trying to send a regex through an api:execute call. -MC
Hello! Thank You, Michael! I'll try your recipe.
On Mon, Apr 18, 2011 at 9:35 AM, Boris Kovalenko <boris@tagnet.ru <mailto:boris@tagnet.ru>> wrote:
Hello!
Yes, I know about LUA native patterns. Unfortunatelly I can't (or don't know how to) do something like: \d{4,6} or \d{10,}
\d{4,6} is "%d%d%d%d%d?%d?"
\d{10,} is "%d%d%d%d%d%d%d%d%d%d+"
At first glance that may seem inelegant, however, it is far more efficient than trying to send a regex through an api:execute call.
-MC
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- ? ?????????, ????? ????????? ??? "??????" ???. +7 (3435) 230001 ???? +7 (3435) 230005
participants (2)
-
Boris Kovalenko
-
Michael Collins