[Freeswitch-users] LUA pattern again

Boris Kovalenko boris at tagnet.ru
Fri Apr 22 05:33:02 MSD 2011


Thank You, Michael! Another way is use more specific LUA patterns.
>
>
> On Thu, Apr 21, 2011 at 10:41 AM, Boris Kovalenko <boris at tagnet.ru 
> <mailto:boris at tagnet.ru>> wrote:
>
>     No success. I use it with string.match function, is it right?
>
> Okay, this is a limitation in Lua's pattern matching. Evidently you 
> cannot use ? on a group like you can in PCRE. So in this case you can 
> use an API call to regex. I wrote a mini test script to demonstrate.
>
> Have fun. :)
> -MC
>
> -- 
> -- pattern.lua
> -- 
> -- Simple Lua pattern testing
> api = freeswitch.API();
> str_pattern = "(3435)230%d%d%d";
> my_str = "73435230111"
> str_regex = "^(7?3435)?230\\d\\d\\d$";
> res = api:execute("regex",my_str .. "|" .. str_regex);
> stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n");
> my_str = "3435230111";
> res = api:execute("regex",my_str .. "|" .. str_regex);
> stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n");
> my_str = "230111";
> res = api:execute("regex",my_str .. "|" .. str_regex);
> stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n");
> my_str = "987230111";
> res = api:execute("regex",my_str .. "|" .. str_regex);
> stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n");
> Output:
> freeswitch at internal> lua pattern.lua
> string: 73435230111, regex result: true
> string: 3435230111, regex result: true
> string: 230111, regex result: true
> string: 987230111, regex result: false
>
>
> _______________________________________________
> 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


-- 
? ?????????,
   ????? ?????????
   ??? "??????"
   ???. +7 (3435) 230001
   ???? +7 (3435) 230005

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


More information about the FreeSWITCH-users mailing list