From: Todd Benson Date: 2008-12-18T07:56:24+09:00 Subject: Re: gsub("\\", "\\\\") seems unintuitive On Wed, Dec 17, 2008 at 3: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. You are looking at a string with escaping characters (i.e. what it would look like in double quotes). You can verify this by using #puts or "joe.com".gsub('.', '\.').length. hth, Todd