<p>The Python docs say:</p>

<blockquote>
  <p>re.MULTILINE: When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline)... By default, '^' matches only at the beginning of the string...</p>
</blockquote>

<p>So what's going on when I get the following unexpected result?</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; s = """// The quick brown fox.
... // Jumped over the lazy dog."""
&gt;&gt;&gt; re.sub('^//', '', s, re.MULTILINE)
' The quick brown fox.\n// Jumped over the lazy dog.'
</code></pre>

Look at the definition of
```
re.sub
```
:
```
```
re.sub(pattern, repl, string[, count, flags])
```
```
The 4th argument is the count, you are using
```
re.MULTILINE
```
(which is 8) as the count, not as a flag.
Either use a named argument:
```
```
re.sub('^//', '', s, flags=re.MULTILINE)
```
```
Or compile the regex first:
```
```
re.sub(re.compile('^//', re.MULTILINE), '', s)
```
```