<br><br><div class="gmail_quote">On Thu, Apr 21, 2011 at 10:41 AM, Boris Kovalenko <span dir="ltr">&lt;<a href="mailto:boris@tagnet.ru">boris@tagnet.ru</a>&gt;</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&#39;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="&#39;courier new&#39;, monospace">--                                                                                                                                                              </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-- pattern.lua                                                                                                                                                  </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">--                                                                                                                                                              </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-- Simple Lua pattern testing                                                                                                                                   </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">api = freeswitch.API();                                                                                                                                         </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">str_pattern = &quot;(3435)230%d%d%d&quot;;                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">my_str = &quot;73435230111&quot;                                                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">str_regex = &quot;^(7?3435)?230\\d\\d\\d$&quot;;                                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">res = api:execute(&quot;regex&quot;,my_str .. &quot;|&quot; .. str_regex);                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">stream:write(&quot;string: &quot; .. my_str .. &quot;, regex result: &quot; .. res .. &quot;\n&quot;);                                                                                        </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">my_str = &quot;3435230111&quot;;                                                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">res = api:execute(&quot;regex&quot;,my_str .. &quot;|&quot; .. str_regex);                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">stream:write(&quot;string: &quot; .. my_str .. &quot;, regex result: &quot; .. res .. &quot;\n&quot;);                                                                                        </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">my_str = &quot;230111&quot;;                                                                                                                                              </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">res = api:execute(&quot;regex&quot;,my_str .. &quot;|&quot; .. str_regex);                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">stream:write(&quot;string: &quot; .. my_str .. &quot;, regex result: &quot; .. res .. &quot;\n&quot;);                                                                                        </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">                                                                                                                                                                </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">my_str = &quot;987230111&quot;;                                                                                                                                           </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">res = api:execute(&quot;regex&quot;,my_str .. &quot;|&quot; .. str_regex);                                                                                                          </font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">stream:write(&quot;string: &quot; .. my_str .. &quot;, regex result: &quot; .. res .. &quot;\n&quot;);                                                                                        </font></div>
<div>                                                                                                                                                                </div><div>Output:</div></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">freeswitch@internal&gt; lua pattern.lua</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">string: 73435230111, regex result: true</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">string: 3435230111, regex result: true</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">string: 230111, regex result: true</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">string: 987230111, regex result: false</font></div>
<div><br></div></div></div>