Werid, the same expression gives a different meaning when requested twice in irb
2 answers
irb(main):001:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,"#{$1} ?") => "ts_id ?" irb(main):002:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,"#{$1} ?") => "ts_id < ?" Note that I used a fresh starting irb where $1 was nil . This is because when using .gsub(...,..$1..) when calculating the "part to the right of , " $1 not generated by the "left part of , ".
Do this:
irb(main):001:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,'\1 ?') => "ts_id < ?" Or that:
irb(main):001:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/){"#{$1} ?"} => "ts_id < ?" +2