擅长:python、mysql、java
<p>你可以用</p>
<pre><code>re.sub(r'([^\W\d_])(\d)', r'\1 \2', s, flags=re.U)
</code></pre>
<p>注意,在python3.x中,<code>re.U</code>标志是多余的,因为默认情况下模式是Unicode感知的。你知道吗</p>
<p>参见<a href="https://ideone.com/c6m43D" rel="nofollow noreferrer">online Python demo</a>和<a href="https://regex101.com/r/E7w3IF/1" rel="nofollow noreferrer">regex demo</a>。你知道吗</p>
<p><strong>图案细节</strong></p>
<ul>
<li><code>([^\W\d_])</code>-捕获组1:任何Unicode字母(字面上,除了非单词、数字或下划线字符以外的任何字符)</li>
<li><code>(\d)</code>-捕获组2:任何Unicode数字</li>
</ul>
<p>替换模式是组1和组2占位符(指相应的捕获值)的组合,它们之间有一个空格。你知道吗</p>
<p>您可以使用带有前瞻性的regex变体:</p>
<pre><code>re.sub(r'[^\W\d_](?=\d)', r'\g<0> ', s)
</code></pre>
<p>见<a href="https://regex101.com/r/E7w3IF/2" rel="nofollow noreferrer">this regex demo</a>。你知道吗</p>