Hello --

On Thu, 11 Apr 2002, Ralph Mason wrote:

> Am I rignt in "~, More" is incorrect?

No, it's correct, because to interpolate the captured things from the
match, you have to use \1, \2, etc.:

  irb(main):001:0> x = "\"CommaTest, After\", More"
  "\"CommaTest, After\", More"
  irb(main):002:0> x.gsub!(/"(.*),(.*)"/,'\1~\2')
  "CommaTest~ After, More"

unless you use the block form of gsub!, in which case you can do:

  irb(main):013:0> x.gsub!(/"(.*),(.*)"/) { "#{$1}~#{$2}" }
  "CommaTest~ After, More"

(Note that you don't need to escape the "'s in the regex.)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav