<p>你可以用</p>
<pre><code>r'(?m)^\[Term].*(?:\r?\n(?!\[(?:Typedef|Term)]).*)*'
</code></pre>
<p>参见<a href="https://regex101.com/r/chozOP/1" rel="nofollow noreferrer">regex demo</a></p>
<p><strong>详细信息</strong></p>
<ul>
<li><code>(?m)</code>-多行修饰符</li>
<li><code>^</code>-行首</li>
<li><code>\[Term]</code>-a<code>[Term]</code>子串</li>
<li><code>.*</code>-当前行的其余部分</li>
<li><code>(?:\r?\n(?!\[(?:Typedef|Term)]).*)*</code>-0次或多次出现:
<ul>
<li><code>\r?\n(?!\[(?:Typedef|Term)])</code>-不跟<code>[Typedef]</code>或<code>[Term]</code>子字符串的换行符(CRLF或LF)</li>
<li><code>.*</code>-当前行的其余部分</li>
</ul></li>
</ul>
<p><a href="https://ideone.com/62iola" rel="nofollow noreferrer">Python code</a>:</p>
^{pr2}$
<p>输出:</p>
<pre><code>[Term]
id: GO:0000001
name: mitochondrion inheritance
namespace: biological_process
def: "The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton." [GOC:mcc, PMID:10873824, PMID:11389764]
synonym: "mitochondrial inheritance" EXACT []
is_a: GO:0048308 ! organelle inheritance
is_a: GO:0048311 ! mitochondrion distribution
Next match -
[Term]
id: GO:0000002
name: mitochondrial genome maintenance
namespace: biological_process
def: "The maintenance of the structure and integrity of the mitochondrial genome; includes replication and segregation of the mitochondrial chromosome." [GOC:ai, GOC:vw]
is_a: GO:0007005 ! mitochondrion organization
Next match -
[Term]
id: GO:0000011
name: vacuole inheritance
namespace: biological_process
def: "The distribution of vacuoles into daughter cells after mitosis or meiosis, mediated by interactions between vacuoles and the cytoskeleton." [GOC:mcc, PMID:10873824, PMID:14616069]
is_a: GO:0007033 ! vacuole organization
is_a: GO:0048308 ! organelle inheritance
Next match -
Number of mathes: 3
</code></pre>