擅长:python、mysql、java
<p>尝试:</p>
<pre><code>import re
p = re.compile(ur'[\r?\n]')
test_str = u"(2 months)\n\nML"
subst = u"_"
result = re.sub(p, subst, test_str)
</code></pre>
<p>它会将字符串减少到</p>
^{pr2}$
<p>见<a href="https://regex101.com/r/oE9iV3/1" rel="nofollow">Demo</a></p>