也许可以试试抛开正则,使用split:
#!/bin/env python
fileH = open("test")
listSec1 = []
ret = []
fileContent = fileH.read()
for s in fileContent.split("test"):
listSec1.append(s)
for s in listSec1[1].split("O_4 #1"):
ret.append(s)
print ret[0]
fileH.close()
温馨提示:答案为网友推荐,仅供参考