From: ahoward@... (ara howard) Date: 2002-01-29T02:58:31+09:00 Subject: problems with string interpolation i'd like do a gsub such that some characters are escapes for later use by system commands, eg: 'a - b &\c' >> 'a\ \-\ b\ \&\\c' A-Za-z remain unaffected but 'special' chars are escaped and while this works fine s = 'a - b &\c' # the string e = '\\' # the escape chr : \ s.gsub(%r{([^A-Za-z])}) {|m| e + $1} >> 'a\ \-\ b\ \&\\c' # ok !! this does not?? s.gsub %r{([^A-Za-z])}, '\\\1' >> 'a\1\1\1b\1\1\1c' # huh ?? and s.gsub %r{([^A-Za-z])}, '\\1' or s.gsub %R{([^A-Za-Z])}, '\1' both leave s *unchaged* it seems in the first non-working case ('\\\1') that the interpolation happens twice : '\\\1' -> '\\1' # 1st '\\' collapsed then starting *again* at the front! huh? '\\1' -> '\1' # 2nd '\\' collapsed but *not* starting again here? '\1' -> '\1' # because '\' was already treated it seems like there is an error in the 2nd line since the first of the '\'s had already been treated once, the interpolation should have moved on to the '\1' by the same logic as the '\1' was not a *real* '\1' because it's '\' was got by interpolation in the third (correctly treated?) line. i'm pretty sure this won't make any sense in writing but hopefully the examples will shed light on this !$&#@ sub\ j\e\ c\ t. basically, it seems like the interpolation should have stopped after line one with '\\1' as the result, and then the substitution step would have yielded '\' instead of it's '\1' ??? -ara