擅长:python、mysql、java
<p>你想逃离你的搜索模式<a href="http://www.regular-expressions.info/brackets.html" rel="nofollow">because parenthesis are special characters in regular expressions</a>。您可以使用<a href="https://docs.python.org/2/library/re.html#re.escape" rel="nofollow">^{<cd1>}</a>轻松完成此操作。在</p>
<pre><code>out = re.sub(re.escape(c), eval(c.lower()), line)
</code></pre>
<p>举个例子:</p>
^{pr2}$
<p>既然如此,为什么不直接使用<code>replace()</code>?在</p>
<pre><code>out = line.replace(c, eval(c.lower())
</code></pre>