[Freeswitch-users] regexp with LUA script

Boris Kovalenko boris at tagnet.ru
Mon Apr 18 20:35:24 MSD 2011


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 at 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 at tagnet.ru 
> <mailto:boris at 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 at lists.freeswitch.org
>     <mailto: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
>
>
>
> _______________________________________________
> 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


-- 
Regards,
Boris


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20110418/e59f36a3/attachment-0001.html 


More information about the FreeSWITCH-users mailing list