> To make it work with scan just make the parens non-capturing:
> 
> irb(main):001:0> text = "#begin aaa end bbb } ccc } #begin ddd end eee 
> end fff"
> => "#begin aaa end bbb } ccc } #begin ddd end eee end fff"
> irb(main):002:0> text.scan(/#begin(?:.*?(?:\}|end)){2}/m)
> => ["#begin aaa end bbb }", "#begin ddd end eee end"]

Ha! That was the trick I have been looking for! Muchas Gracias, Carlos.

Cheers,
Peter

__
http://www.rubyrailways.com