From: Glen Holcomb Date: 2008-12-18T06:20:47+09:00 Subject: Re: gsub("\\", "\\\\") seems unintuitive ------=_Part_25523_30638082.1229549317466 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wed, Dec 17, 2008 at 2:12 PM, Joe Peck wrote: > Joe Peck wrote: > > I stumbled onto this thread trying to figure out a similar problem... > > Dangit, I didn't mean to post the above message :) > > Okay, I need to read a site name (like "joe.com") and put a \ in front > of the period (so it would be "joe\.com"). I'm having trouble with > this, I can't seem to get only ONE \ in front of the period... > > >> "joe.com".gsub(/\./, "\\\.") > => "joe\\.com" > >> "joe.com".gsub(/\./, "\\\\.") > => "joe\\.com" > > Anyone have a clue what to do? I'm probably missing something simple. > -- > Posted via http://www.ruby-forum.com/. > > That's because you are in irb. You are getting what you want try this: puts "joe.com".gsub(/\./, "\\\\.") Actually it might be more readable as gsub('.', '\.') -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_25523_30638082.1229549317466--