re.S

如果不使用re.S参数,则只在每一行内进行匹配,如果一行没有,就换下一行重新开始。

而使用re.S参数以后,正则表达式会将这个字符串作为一个整体,在整体中进行匹配。

 

import re
a = """sdfkhellolsdlfsdfiooefo:
877898989worldafdsf"""
b = re.findall('hello(.*?)world',a)
c = re.findall('hello(.*?)world',a,re.S)
print ('b is ' , b)
print ('c is ' , c)


# 输出结果:
# b is []
# c is ['lsdlfsdfiooefo:\n877898989']

posted @ 2021-11-24 10:13  冰溏  阅读(156)  评论(0编辑  收藏  举报