From: jOhn Date: 2008-02-09T07:20:37+09:00 Subject: Re: regex dynamic count modifier {min, max} ? ------=_Part_46364_30815498.1202509243454 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I modified slightly to avoid parenthesis within quotes or double quotes def get_fns(string, count=0) m = /(? fn:[\w\-]+ \s*\(\s* (\g|(".+")*('.+')*[^)]*) \s*\) )\s*/xi.match(string) if m n = /^(fn:[\w\-]+)(\s*)\((.*?)\)$/.match(m['fn']) puts "FN #{count}: #{n[1]} with args #{n[3]}" get_fns(n[3], count + 1) end end On Feb 8, 2008 7:39 AM, jOhn wrote: > wow good job thomas. > > On Feb 8, 2008 1:19 AM, tho_mica_l wrote: > > > > To parse a logic statement like this: > > > > > > fn:function3(fn:function2(fn:function1(xargs))) > > > > Are you looking for something like this (ruby19): > > > > def get_fns(string, count=0) > > m = /(? > > fn:[\w\-]+ > > \s*\(\s* > > (\g|[^)]*) > > \s*\) > > )\s*/xi.match(string) > > if m > > n = /^(fn:[\w\-]+)(\s*)\((.*?)\)$/.match(m['fn']) > > puts "FN #{count}: #{n[1]} with args #{n[3]}" > > get_fns(n[3], count + 1) > > end > > end > > a = "foo fn:function3(fn:function2(fn:function1(xargs))) foo(bar) bar" > > get_fns(a) > > > > > a = "foo fn:function3(fn:function2(fn:function1(xargs))) foo(bar) bar" > > > get_fns(a) > > FN 0: fn:function3 with args fn:function2(fn:function1(xargs)) > > FN 1: fn:function2 with args fn:function1(xargs) > > FN 2: fn:function1 with args xargs > > => nil > > > > Regards, > > Thomas. > > > > > > > ------=_Part_46364_30815498.1202509243454--