天天看点

What's the difference between re.DOTALL and re.MULTILINE? [duplicate]

what's the difference between re.dotall and re.multiline? [duplicate]

they are quite different. yes, both affect how newlines are treated, but they switch behaviour for different concepts.

<code>re.multiline</code> affects where <code>^</code> and <code>$</code> anchors match.

without the switch, <code>^</code> and <code>$</code> match only at the start and end, respectively, of the whole text. with the switch, they also match just before or after a newline:

<code>re.dotall</code> affects what the <code>.</code> pattern can match.

without the switch, <code>.</code> matches any character except a newline. with the switch, newlines are matched as well:

继续阅读