【发布时间】:2016-04-04 05:32:27
【问题描述】:
我有一个包含某些规则的文本文件。这是它的格式:
:SchoolName (rule_1)
)
:xyz (true)
:abc_efg (
: xxyyzz-x1y1-z1z2-z3z4
)
- 我想匹配 ':abc_efg' 并在匹配后得到行,即 ':xxyyzz-x1y1-z1z2-z3z4'
- 每次有新文件时,它都会查找 ':abc_efg' 并在匹配后得到相应的行
到目前为止我已经尝试过
with open('G:\CM\Python Exercises\Project_F\abc.txt') as f:
text = f.read()
list1=text.strip('\n\t').split(':')
print list1
for line in list1:
if ':abc_efg' in list1:
print line
print '\n'.join(list1[i+1])
打印列表1显示
[':abc_efg (\n\t\t\t', ': xxyyzz-x1y1-z1z2-z3z4 \n\t\t)\n\t\t']
【问题讨论】:
标签: python pattern-matching generator regex-lookarounds