如何使用Python正则表达式匹配除空格和换行外的任何字符?
以下代码使用正则表达式在给定字符串中匹配除空格和换行符外的任何字符。
阅读更多:Python 教程
示例
import re
print re.match(r'^[^ \n]*', """IfindTutorialspointuseful""")
print re.match(r'^[^ \n]*', """I find Tutorialspointuseful""")
print re.match(r'^[^ \n]*$', """Ifind
Tutorialspointuseful""")
输出
该代码的输出结果如下:
<_sre.SRE_Match object at 0x00000000048965E0>
None
None