tommorris (owner)

Revisions

gist: 183061 Download_button fork
public
Public Clone URL: git://gist.github.com/183061.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
# if you have to do particularly gnarly XML handling, you often have to double-encode
# ampersands. Of course, ideally, you'd use CDATA sections to avoid this. But, alas,
# life ain't that easy. Here's a simple regex to enable you to replace "&" with
# "&" unless, of course, it already IS that.
 
def double_encode_ampersads(string)
  string.gsub(/(&)(?!amp;)/, "\\1amp;")
end
 
# if you are doing this at the shell to large numbers of files, just use sed:
# `sed 's/(&)(?!amp;)/\\1amp;/g'`