From: ts Date: 2002-10-01T20:36:50+09:00 Subject: Re: regex problem >>>>> "P" == =?iso-8859-1?Q?Peter Sch=FCller?= writes: P> i want to substitute one \ with two \\ It's in the faq, see http://www.rubycentral.com/faq/rubyfaq-9.html#ss9.18 Regexp.quote('\\') escapes a backslash. It gets trickier if you're using sub and gsub, Say you write gsub(/\\/, '\\\\'), hoping to replace each backslash with two. The second argument is converted to '\\' in syntax analysis. When the substitution occurs, the regular expression engine converts this to '\', so the net effect is to replace each single backslash with another single backslash. You need to write gsub(/\\/, '\\\\\\')! However, using the fact that \& contains the matched string, you could also write gsub(/\\/, '\&\&'). If you use the block form of gsub, i.e. gsub(/\\/){'\\\\'}, the string for substitution is analyzed only once (during the syntax pass) and the result is what you intended. Guy Decoux