title: A regular expression to clean up XML
body: <p>I have to deal with XML data that sometimes contains the unescaped ampersand and I can't get the producer to either escape it to &amp; or put it into a CDATA section.</p>
  
  <p>Now I'm looking for a regular expression to replace &amp; with &amp; amp; if its not part of an entity. Something like this: &amp;(?!(amp|apos|quot|lt|gt);)</p>
  
  <p>Unfortunately, my programming environment only support "extended POSIX 1003.2 regular expressions" (see <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/regex.7.html" rel="nofollow">http://www.kernel.org/doc/man-pages/online/pages/man7/regex.7.html</a>) which seem to lack the not operator "!" needed here.</p>
  
  <p>Any ideas how to craft the necessary regular expression ?</p>