Why doesn't this work?!
re.match(r".*hello.*", "\n\nhello\n\n", re.MULTILINE)
Help please?
Windows 7 x64 Python 2.7.3
You are looking for re.DOTALL
instead:
re.match(r".*hello.*", "\n\nhello\n\n", re.DOTALL)
Quoting the documentation:
Make the
'.'
special character match any character at all, including a newline; without this flag,'.'
will match anything except a newline.
re.MULTILINE
alters where ^
and $
match, not what the .
dot pattern matches.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.