From: jOhn Date: 2008-02-09T00:39:48+09:00 Subject: Re: regex dynamic count modifier {min, max} ? ------=_Part_43433_3262307.1202485194270 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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_43433_3262307.1202485194270--