From: Robert Klemme Date: 2004-03-16T22:49:40+09:00 Subject: Re: reg multi match replace "Simon Strandgaard" schrieb im Newsbeitrag news:pan.2004.03.16.10.50.19.188882@adslhome.dk... > 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. While we're at it: you also don't need the outer brackets. > > > @value.gsub!(/(\{\{(\w+?)\}\})/) do > @values[$2] > end @value.gsub!(/\{\{(\w+?)\}\}/) do @values[$1] end ;-) robert