From: Simon Strandgaard Date: 2004-03-16T19:59:38+09:00 Subject: Re: reg multi match replace On Tue, 16 Mar 2004 12:18:43 +0900, Paul Vudmaska wrote: > i'm still a noob and had the need for a simple template system and thot > it would be a nice learning experience. all i want to do is replace > {{VALUES}} > with the hash value of the same name eg hValues[VALUES]. So i thot well > this probably aint easy and i sat down and came up with this > > @value.gsub!(/(\{\{(.+)\}\})/) { > > @values[$2] > } > A few hints. ".+" is greedy. You would want to use non-greedy ".+?" "." is matching anything else than newline, which easily may match too much. Instead use "\w" which only matches alphanumeric characters. @value.gsub!(/(\{\{(\w+?)\}\})/) do @values[$2] end -- Simon Strandgaard