From: Peter Hickman Date: 2003-01-27T18:44:41+09:00 Subject: Very nasty piece of code Whilest writing my RTF tools library I had a need to convert from &#XX; (XML entity style) into \'XX (RTF entity style). I ended up with this monstrosity... while string =~ /(&#([0-9a-fA-F]{2});)/ do # Converting from &#XX; to \'XX string.sub!($1, "\\\\\\\''#{$2}") end It seems to work but what is going on here? It looks like Java or TCL on a bad day and was only arrived at by adding random numbers of \ and ' until it worked. Surely there is a better way to do this.