title: Python regular expression to strip script tags
body: <p>I'm a little scared to ask this for fear of retribution from the SO "You can't parse HTML with regular expressions" cult. Why does <code>re.subn(r'&lt;(script).*?&lt;/\1&gt;', '', data, re.DOTALL)</code> not strip the multiline 'script' but only the two single-line ones at the end, please?</p>
  
  <p>Thanks, HC</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; data = """\
  &lt;nothtml&gt; 
    &lt;head&gt; 
      &lt;title&gt;Regular Expression HOWTO &amp;mdash; Python v2.7.1 documentation&lt;/title&gt; 
      &lt;script type="text/javascript"&gt; 
        var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../',
          VERSION:     '2.7.1',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html',
          HAS_SOURCE:  true
        };
      &lt;/script&gt; 
      &lt;script type="text/javascript" src="../_static/jquery.js"&gt;&lt;/script&gt; 
      &lt;script type="text/javascript" src="../_static/doctools.js"&gt;&lt;/script&gt;
  """
  
  &gt;&gt;&gt; print (re.subn(r'&lt;(script).*?&lt;/\1&gt;', '', data, re.DOTALL)[0])
  &lt;nothtml&gt; 
    &lt;head&gt; 
      &lt;title&gt;Regular Expression HOWTO &amp;mdash; Python v2.7.1 documentation&lt;/title&gt; 
      &lt;script type="text/javascript"&gt; 
        var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../',
          VERSION:     '2.7.1',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html',
          HAS_SOURCE:  true
        };
      &lt;/script&gt; 
  </code></pre>