title: Need RE to detect UTF-8
body: <p>I have the following code</p>
  
  <pre><code>inf = codecs.open(inPath , encoding='utf-8')
  outf = codecs.open(outPath, encoding='utf-8', mode='w')
  old = u'’;'
  new = u'’&amp;#59;'
  for line in inf:
      line = line.replace(old,new)
      asc = line.encode('ascii', 'xmlcharrefreplace')    
      outf.write(asc)
      # print asc
  inf.close()
  outf.close()
  </code></pre>
  
  <p>This (correctly) converts smart quotes and accented characters etc, into their html entity format, using the numeric format. It will convert</p>
  
  <pre><code>&lt;p&gt;Dreams like: “Someday I’ll travel to…; someday I’ll write a book;
  </code></pre>
  
  <p>into </p>
  
  <pre><code>&lt;p&gt;Dreams like: &amp;#8220;Someday I&amp;#8217;ll travel to&amp;#8230;; someday I&amp;#8217;ll write a book; 
  </code></pre>
  
  <p>This is all correct. </p>
  
  <p>However code further down stream, sees the <code>&amp;#8230;;</code> in the middle, drops the double semi-colon and then complains that it has not got a valid entity. I can't change this code. </p>
  
  <p>As you can see from my code, I have caught one case where an entity is followed by a semi-colon. I don't want to replace all the semi-colons in the source.</p>
  
  <p>How can I detect a semi colon that follows a UTF-8 character with a code point > 127, so that I can replace it with <code>&amp;#59;</code>?  Thanks.</p>