[Freeswitch-users] LUA pattern again
Michael Collins
msc at freeswitch.org
Thu Apr 21 22:16:56 MSD 2011
On Thu, Apr 21, 2011 at 10:41 AM, Boris Kovalenko <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20110421/ca557889/attachment.html
More information about the FreeSWITCH-users
mailing list