Python re.sub MULTILINE caret match
Posted
by cdleary
on Stack Overflow
See other posts from Stack Overflow
or by cdleary
Published on 2008-09-03T21:00:33Z
Indexed on
2010/03/25
16:13 UTC
Read the original article
Hit count: 420
The Python docs say:
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...
So what's going on when I get the following unexpected result?
>>> import re
>>> s = """// The quick brown fox.
... // Jumped over the lazy dog."""
>>> re.sub('^//', '', s, re.MULTILINE)
' The quick brown fox.\n// Jumped over the lazy dog.'
© Stack Overflow or respective owner