擅长:python、mysql、java
<p>Regex是您想要的,但是不要使用<code>match</code>,而是使用<code>sub</code>:</p>
<pre><code>s = f.read()
s = re.sub(r'\n+', '\\n', s)
</code></pre>
<p><a href="https://regex101.com/r/31v3zc/1/" rel="nofollow noreferrer">Example on Regex101</a></p>