Python的正则表达式中,有一个re.S参数。它表示多行匹配
import re lstr="""sdgsafmhellopass 2584614 worldnjhdsdsd """ #在字符串lstr中,包含换行符 ,在这种情况下,若不使用re.S参数,则只在每一行中进行匹配,如果一行没有就换下一行重新开始 当使用re.S参数以后,正则表达式将会将字符串作为一个整体,在整体中进行匹配 m=re.findall("hello(.*?)world",lstr) #(.*?)非贪婪匹配 n=re.findall("hello(.*?)world",lstr,re.S) print ("m is ",m ) print ("n is ",n)
m is []
n is ['pass
2584614
']