Python正则表达式不能像我预期的那样工作

Dar*_*ckt -1 python regex

为什么这不起作用?!

re.match(r".*hello.*", "\n\nhello\n\n", re.MULTILINE)
Run Code Online (Sandbox Code Playgroud)

请帮忙?

Windows 7 x64 Python 2.7.3

Mar*_*ers 6

你正在寻找re.DOTALL:

re.match(r".*hello.*", "\n\nhello\n\n", re.DOTALL)
Run Code Online (Sandbox Code Playgroud)

引用文档:

使'.'特殊字符与任何字符匹配,包括换行符; 没有此标志,'.'将匹配除换行符之外的任何内容.

re.MULTILINE改变位置^$匹配,而不是.点图案匹配.