擅长:python、mysql、java
<p><code>.replace()</code>替换字符串,您需要<code>re.sub(..)</code>,例如:</p>
<pre><code>for line in fi:
if searchString in line:
line2 = re.sub(r'\s' , '\n', line)
print line2
</code></pre>
<p>文档有更多详细信息:<a href="https://docs.python.org/2/library/re.html#re.sub" rel="nofollow">https://docs.python.org/2/library/re.html#re.sub</a></p>