From: Carlos Date: 2006-12-11T18:43:04+09:00 Subject: Re: Regexp/scan question Carlos wrote: > Peter Szinek wrote: > >> Hello, >> >> I need to match a chunk of code like this: >> >> .... >> .... >> #begin here >> ...} >> ......end >> ...} >> ......} >> .....end >> ... >> ... >> >> I need to match from "the #begin here" up to the n-th closing token >> (i.e. '}' or 'end'). n can be arbitrary (let's consider that it is >> meaningful, i.e. there are no more '}' + 'end's than n. > > > n = 4 > text =~ /#begin(.*?(\}|end)){#{n}}/m ^ better with '?', to make it not greedy :).