擅长:python、mysql、java
<p>尝试使用<code>re.sub</code>和lambda表达式</p>
<pre><code>>>> import re
>>> test = '[[this is a page]] bla bla [[this is another page]]'
>>> re.sub(r'\[\[.+?\]\]', lambda x:x.group().replace(" ","_"), test)
'[[this_is_a_page]] bla bla [[this_is_another_page]]'
</code></pre>