--/NkBOFFp2J2Af1nK
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Oct 09, 2006 at 08:58:09PM +0900, Jani Patokallio wrote:
> Greetings,
> 
> I'm trying to do something that should be very simple: stick a "\" in 
> front of
> every instance of "&" in a string.  However, the obvious code...
> 
>   "this&that".gsub!("&", "*")
>   --> "this*that" # OK!
> 
>   "this&that".gsub!("&", "\\&")
>   --> "this&that" # Wrong
> 
> ...doesn't work, because "\&" means "last match" in gsub substitution 
> strings.
> How can I escape this?  I experimentally determined that entering 
> "\\\\\\&"
> (that's six backslashes) gets the desired result, but I don't really
> understand why.  Is there a less obscure way of doing this?

    I'm not sure, but I think that the problem is that you are using double
quotes. So, the value you are passing is really the same as:

    '\\\&'

Which, once you interpret the escape sequences, you have a literal '\' and a
literal '&'...

-- 
Esteban Manchado VeláÛquez <zoso / foton.es> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es

--/NkBOFFp2J2Af1nK
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFKjrxhYgK5b1UDsERAlC8AJsFBEEKmaLIgyjCrc/sDYa+MD34ogCfchCt
HEx/oeI+zaBbLiX7BWDmd1cpl
-----END PGP SIGNATURE-----

--/NkBOFFp2J2Af1nK--