import re
'''
传入re.DOTALL作为re.compile()的第二个参数,让句点字符匹配所有字符,包括换行
'''
noNewlineRegex = re.compile('.*')
a = noNewlineRegex.search('Serve the public trust.\nProtect the innocent.\nUpload the law.').group()
print(a)
print('-----------------')
newlineRegex = re.compile('.*',re.DOTALL)
b = newlineRegex.search('Serve the public trust.\nProtect the innocent.\nUpload the law.').group()
print(b)
结果是:
Serve the public trust.
-----------------
Serve the public trust.
Protect the innocent.
Upload the law.
网友评论