擅长:python、mysql、java
<p>您还可以使用保存组从<code>name['something']</code>中提取字符串:</p>
<pre><code>>>> import re
>>> s = "RSQ(name['BAKD DK'], name['A DKJ'])"
>>> re.sub(r"name\['(.*?)'\]", r"\1", s)
'RSQ(BAKD DK, A DKJ)'
</code></pre>
<p>其中<code>(.*?)</code>是一个<a href="https://docs.python.org/2/howto/regex.html#grouping" rel="nofollow noreferrer">capturing group</a>,它将匹配<a href="https://stackoverflow.com/questions/2301285/what-do-lazy-and-greedy-mean-in-the-context-of-regular-expressions">non-greedy fashion</a>中任意次数的任何字符。<code>\1</code>在替换字符串中引用捕获的组。在</p>