Richard Lionheart wrote: > Hi All, > > The following Ruby script displays use of a pattern to remove a superfluous > backslash in a string if present. It works as intended with two "toy" > situations, but fails when applied to an environment string running under > Windows. > > Can anyone tell me where I erred? > > > s2.chop! if s2.reverse =~ /^\\\\/ > > sCookiesPath.chop! if sCookiesPath.reverse !~ /^\\\\/ You changed =~ to != The reversed path doesn't begin with double slash, so you chop! the single slash. ["xyz\\", "xyz\\\\"].each do |s| puts '----------', s s.chop! if s.reverse =~ /^\\\\/ puts s end # Also: # s.sub!(/\\\\\Z/, '\\') # works for: # s.chop! if s.reverse =~ /^\\\\/ daz