re.DOTALL enabled all the time?
David Rock <[email protected]> Mon, 10 Mar 2025 13:00:39 -0500
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <[email protected]> |
I was trying to help someone understand matching across newlines with . and
came across something strange. Best I can tell, it looks like re.DOTALL is
always active.
>>> mytext = r'ab<c. de fg<hMOD3876Xi\nj>klmnop\nqr. st>uvwxyz'
>>> mytext
'ab<c. de fg<hMOD3876Xi\\nj>klmnop\\nqr. st>uvwxyz'
>>> print(mytext)
ab<c. de fg<hMOD3876Xi\nj>klmnop\nqr. st>uvwxyz
>>> import re
>>> match = re.search('<.*?>',mytext)
>>> match
<re.Match object; span=(2, 26), match='<c. de fg<hMOD3876Xi\\nj>'>
I would have expected this to fail to match because a . should not match a newline and never find seriously >
A few questions:
if re.DOTALL is baked in somehow, how do you disable it? Setting re.NOFLAG doesn't do it
is there a way to see what flags were used in a match/search?
when did this behavior change?
--
David Rock
[email protected]
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor