From: Paul Vudmaska Date: 2004-03-17T02:43:58+09:00 Subject: Re: reg multi match replace David A. Black wrote: >Hi -- > >On Wed, 17 Mar 2004, Paul Vudmaska wrote: > > > >>David A. Black wrote: >> >> >> >>>Another small suggestion: it doesn't look like you need two captures (unless >>>you're doing something with $1 that isn't revealed here): >>> >>> @value.gsub!(/(\{\{(.+?)\}\})/) { @values[$1] } >>> >>> ^^^ >>> (or \w+? if wanted) >>> >>> >>>David >>> >>> >>> >>> >>> >>Thanks David, Soon after i fired the email i noticed it did not work on >>lines with 2 tokens {{one}} {{two}} so adding the ? worked great! About >>the inner capture, the outer one matched {{match}} and i needed just the >>name - match - which matches the hash i pass to the template >>{'match'=>'match value'}. Using @values[$2] matched the inner one. To be >>honest, i did not know what $2 was, when i was considering my >>options(like replacing {}), but then i thot "there's a $1 there must be >>a $2" - and it worked after i put the inner capture. i thot it was >>great -and a testament to the goodness of all this! The names that will >>be in the tokens and hashes will be like 'name', 'client.name'. So per >>your suggestion i changed it to /(\{\{([\w\.]+?)\}\})/ which >>accomodates the dot and is more concise to boot. Appreciate your help :0) >> >> > >The thing is, you don't need an inner and outer match in the first >place, if all you want is the inner stuff. You're just saving an >extra piece of data that you're not using. > > >David > > > Right, David, now i see that - pretty cool, thanks! :P