<p>与<code>bash</code>正则表达式不同,<code>*</code>不是通配符,而是表示将前面的内容重复0次或更多次。你知道吗</p>
<p>在正则表达式中,您的<code>*</code>没有要修改的符号,因此您看到了投诉<code>nothing to repeat</code>。你知道吗</p>
<p><strong>另一方面</strong>如果提供<code>.</code>符号供<code>*</code>修改,以一行测试为例</p>
<pre><code>eachLine = '#ps_RDW_Conn.jp_RDW_SCHEMA_NAME#.P_PO_RCPT_DTL a, (SELECT PO_RCPT_DTL_KEY, '
re.findall('#(.*?)#', eachLine)
</code></pre>
<p>我们得到</p>
<pre><code>['ps_RDW_Conn.jp_RDW_SCHEMA_NAME']
</code></pre>
<p><strong>更多细节。</strong>
我不确定这是否是你想要的,但是你的<code>*?</code>实际上是很好的位置。
<code>*?</code>被解释为一个限定词,它表示<em>将前面的事情重复0次或更多次,但要尽可能少地使用</em>。你知道吗</p>
<p>因此,这最终会产生类似于@tobias_k在评论中所建议的效果,防止多个群体被吸收到一个群体中。你知道吗</p>
<pre><code>>>> line = 'And here is # some interesting code #, where later on there are #fruit flies# ?'
>>> re.findall('#(.*)#', line)
[' some interesting code #, where later on there are #fruit flies']
>>>
>>> re.findall('#(.*?)#', line)
[' some interesting code ', 'fruit flies']
>>>
</code></pre>
<p>如需参考,请浏览<a href="https://docs.python.org/2/howto/regex.html#repeating-things" rel="nofollow">Repeating Things in docs.python.org</a></p>