From: Robert Klemme Date: 2008-03-25T19:27:24+09:00 Subject: Re: Replacing part of a matched regular expression using gsub 2008/3/25, Ben : > Hi Jesus, > > > > Hi, it works for me: > > > > irb(main):009:0> replacement = "\\1102\\3," > > => "\\1102\\3," > > irb(main):010:0> word = "qweraxbtyuiop" > > => "qweraxbtyuiop" > > irb(main):011:0> word.gsub!(Regexp.new("(a)(x)(b)"), replacement) > > => "qwera102b,tyuiop" > > > > Hope this helps, > > > > Jesus. > > > Thank you! Actually, that did help, as it made me realise that what I > needed to do was try it out in irb. I got it to work now - thanks! > (For the record, the problem was that rule.getRegExp was returning > "(a)x(b)" instead of "(a)(x)(b)"). I'd prefer the first one because you do not need the second group as far as I can see. So I'd do str.gsub!( /(a)x(b)/, '\\1102,\\2' ) Kind regards robert -- use.inject do |as, often| as.you_can - without end