From: Joel VanderWerf Date: 2010-06-29T03:53:23+09:00 Subject: Re: Regex.escape bug Tasos Laskos wrote: > Hi guys, > > I'm using "ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]" > and just noticed a possible bug in Regex.escape() while using it with > gsub() > > > This: > -------- > pp Regexp.escape( '.rb' ) > -------- > > yields: > -------- > "\\.rb" > -------- > > while it should be "\.rb". > > Regexp.new( '.rb' ) or Regexp.new( '\.rb' ) work though, they replaces > the ".rb" string as expected. > Yes I know that "Regexp.new( '.rb' )" works incidentally but I'm just > mentioning it. :) It is correct, because it lets you do this: >> dot_rb = Regexp.escape( '.rb' ) => "\\.rb" >> /file#{dot_rb}/ =~ "file.rb" => 0 >> /file#{dot_rb}/ =~ "fileQrb" => nil Note that "\\.rb" is the same string as '\.rb'.