擅长:python、mysql、java
<p>您可能想在<code>re.sub</code>中使用捕获组和反向引用。您也不需要转义替换字符串(<strong><a href="https://regex101.com/r/RzN4mV/1" rel="nofollow noreferrer">regex101</a></strong>):</p>
<pre><code>import re
s = '''It reported the proportion of the edits made from America was 51% for the Wikipedia, and 25% for the simple Wikipedia.[142] The Wikimedia Foundation hopes to increase the number in the Global South to 37% by 2015.[143] '''
x = re.sub(r'\.\[([0-9]{2,5})\]\s', r'.[\1] \n', s)
print(x)
</code></pre>
<p>印刷品:</p>
^{pr2}$