The Python docs say:
re.MULTILINE: When specified, the pattern character \'^\' matches at the beginning of the string and at the beginning of each lin
re.sub('(?m)^//', '', s)
The full definition of re.sub is:
re.sub(pattern, repl, string[, count, flags])
Which means that if you tell Python what the parameters are, then you can pass flags
without passing count
:
re.sub('^//', '', s, flags=re.MULTILINE)
or, more concisely:
re.sub('^//', '', s, flags=re.M)
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)