老师你好,Python 正则表达式匹配test与O_4 #1字符之间的字符,每次都是输出#2
文件内容hello.txt:
s=test_start
FUNCsfasdsdfasdfafsdfasTIfsdfsdON : O_3
FUNfdfasdTIf asON : O_4 #1
FUNCsfasdsdfasdfafsdfasTIfsdfsdON : O_3
FUNfdfasdTIf asON : O_4 #2
import re
s = open('hello.txt').read()
c = re.findall(r"test(.*)O_4", s, re.MULTILINE | re.DOTALL)
for x in c:
print(x)
import re
s = open('hello.txt').read()
c = re.findall(r"test*?(.*)O_4*?", s, re.MULTILINE | re.DOTALL)
for x in c:
print(x)
加了*?为什么没有作用?