美文网首页
正则_句点统配换行

正则_句点统配换行

作者: 测试媛617 | 来源:发表于2018-08-21 15:24 被阅读0次
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.

相关文章

网友评论

      本文标题:正则_句点统配换行

      本文链接:https://www.haomeiwen.com/subject/hjkjiftx.html