擅长:python、mysql、java
<p>不确定整场比赛都需要正则表达式。我只需要使用正则表达式来匹配<code>**</code>行,然后返回行,直到看到下一行<code>**</code>。你知道吗</p>
<p>像这样的</p>
<pre><code>pattern = re.compile("\*\* "+ head)
start = False
output = []
for line in my_file:
if pattern.match(line):
start = True
continue
elif line.startswith("**"): # but doesn't match pattern
break
if start:
output.append(line)
# now `output` should have the lines you want
</code></pre>