From: Paul Mckibbin Date: 2008-03-25T11:07:16+09:00 Subject: Re: Replacing part of a matched regular expression using gsu Rodrigo Bermejo wrote: > word.gsub!(/axb/) {"102,"} Except that will consume the a and b in addition to the x. Try: word = "groupaxbas" word.gsub!(/(a)x(?=b)/,'\1102,') p word Unfortunately, Ruby's regex processor doesn't seem to have the zero width positive lookbehind, so I couldn't quite work out how not to consume the preceding 'a', so I needed to group and replace it. Zero width positive lookahead and negative lookahead both seem to work ok, although I've yet to see any documentation on these. Mac -- Posted via http://www.ruby-forum.com/.