<br><br><div class="gmail_quote">On Thu, Apr 21, 2011 at 10:41 AM, Boris Kovalenko <span dir="ltr"><<a href="mailto:boris@tagnet.ru">boris@tagnet.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#ffffff">
No success. I use it with string.match function, is it right?<div><div></div><div class="h5"><br></div></div></div></blockquote><div>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.</div>
<div><br></div><div>Have fun. :)</div><div>-MC</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">-- </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- pattern.lua </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- Simple Lua pattern testing </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">api = freeswitch.API(); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">str_pattern = "(3435)230%d%d%d"; </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">my_str = "73435230111" </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">str_regex = "^(7?3435)?230\\d\\d\\d$"; </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">res = api:execute("regex",my_str .. "|" .. str_regex); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n"); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">my_str = "3435230111"; </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">res = api:execute("regex",my_str .. "|" .. str_regex); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n"); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">my_str = "230111"; </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">res = api:execute("regex",my_str .. "|" .. str_regex); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n"); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">my_str = "987230111"; </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">res = api:execute("regex",my_str .. "|" .. str_regex); </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">stream:write("string: " .. my_str .. ", regex result: " .. res .. "\n"); </font></div>
<div> </div><div>Output:</div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">freeswitch@internal> lua pattern.lua</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">string: 73435230111, regex result: true</font></div><div><font class="Apple-style-span" face="'courier new', monospace">string: 3435230111, regex result: true</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">string: 230111, regex result: true</font></div><div><font class="Apple-style-span" face="'courier new', monospace">string: 987230111, regex result: false</font></div>
<div><br></div></div></div>