title: Regex for matching all instances of a word except a specific superstring containing that word
body: <p>I am working on a regex that would match all instances of a word except a specific string that contains that word.</p>
  
  <p>For example, I would like to match all instances of <strong><em><code>stack</code></em></strong> in the following sentence except <strong><em><code>stack.overflow</code></em></strong> (<em>because it is followed by <strong><code>.overflow</code></em></strong>) and replace <strong><em><code>stack</code></em></strong> with <strong><em><code>STACK</code></em></strong></p>
  
  <blockquote>
    <p>This is a stack of pages on stack overflow. Sometimes also referred to
    as stack.overflow.com</p>
  </blockquote>
  
  <p>After performing a replace operation, the above sentence should look like:</p>
  
  <blockquote>
    <p>This is a STACK of pages on STACK overflow. Sometimes also referred to
    as stack.overflow.com</p>
  </blockquote>
  
  <p><strong>Edit:</strong> </p>
  
  <p>To clarify some confusion, I wanted to match all strings that contained <code>stack</code> in all lowercase except a specific situation where <code>stack</code> was followed by <code>.overflow</code>. For example, the following sentence</p>
  
  <blockquote>
    <p>I stacked this stacking stack and re-stacked (stACked it again) but no 
    stack.overflow but stacked.overflow and restacked.overflow</p>
  </blockquote>
  
  <p>should be</p>
  
  <blockquote>
    <p>I STACKed this STACKing STACK and re-STACKed (stACked it again) but no 
    stack.overflow but STACKed.overflow and reSTACKed.overflow</p>
  </blockquote>