From: Peter Szinek Date: 2006-12-11T18:28:27+09:00 Subject: Regexp/scan question 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. Example match_stuff(2): #begin here ...} ......end match_stuff(4): #begin here ...} ......end ...} ......} etc. What's the most optimal way to accomplish this? I have been trying with scan() but I did not really succeed yet TIA, Peter __ http://www.rubyrailways.com