On Thu, Apr 21, 2011 at 10:41 AM, Boris Kovalenko <boris@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@internal> lua pattern.lua string: 73435230111, regex result: true string: 3435230111, regex result: true string: 230111, regex result: true string: 987230111, regex result: false