title: Sed regex and substring negation
body: <p>What is the correct syntax for finding a substring (a string which is preceded and followed by specific strings) which does <strong>not</strong> match a specific pattern?</p>
  
  <p>For example, I want to take all substrings which <em>start</em> with <code>BEGIN_</code>, <em>end</em> with <code>_END</code> and the substring in between is <strong>not</strong> equal to <code>FOO</code>; and replace the whole substring with the format "(<em>inner substring</em>)". The following would match:</p>
  
  <ul>
  <li><code>BEGIN_bar_END</code> -> <code>(bar)</code></li>
  <li><code>BEGIN_buz_END</code> -> <code>(buz)</code></li>
  <li><code>BEGIN_ihfd8f398IHFf9f39_END</code> -> <code>(ihfd8f398IHFf9f39)</code></li>
  </ul>
  
  <p>But <code>BEGIN_FOO_END</code> would not match.</p>
  
  <p>I have played around with the following, but cannot seem to find the correct syntax:</p>
  
  <pre><code>sed -e 's/BEGIN_(^FOO)_END/($1)/g'
  sed -e 's/BEGIN_([^FOO])_END/($1)/g'
  sed -e 's/BEGIN_(?!FOO)_END/($1)/g'
  sed -e 's/BEGIN_(!FOO)_END/($1)/g'
  sed -e 's/BEGIN_(FOO)!_END/($1)/g'
  sed -e 's/BEGIN_!(FOO)_END/($1)/g'
  </code></pre>