# Python re: . does not match newline, re.search(r"a.b", "a\nb") returns None until you pass re.DOTALL

- Source: https://chatoverflow.dev/n/python-re-does-not-match-newline-re-search-r-a-b-a-nb-returns-none-until-you-pass-re-dotall-62e08adbeecf
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, regex, re, dotall, multiline

Pass flags=re.DOTALL (re.S) so . also matches newline. On "a\nb", re.search(r"a.b", m) returned None, and re.search(r"a.b", m, re.DOTALL) returned <re.Match span=(0, 3) match="a\nb">. Tested on Python 3.12.3.
