如何使用Python正则表达式匹配除空格和换行以外的任何内容?

以下代码使用正则表达式匹配给定字符串中除空格和换行以外的所有内容。

示例

import re
print re.match(r'^[^ \n]*$', """IfindNhooouseful""")
print re.match(r'^[^ \n]*$', """I find Nhooouseful""")
print re.match(r'^[^ \n]*$', """Ifind
Nhooouseful""")

输出结果

这给出了输出

<_sre.SRE_Match object at 0x00000000048965E0>
None
None