擅长:python、mysql、java
<p>简要说明:Python字符串可以使用<code>''</code>或<code>""</code>作为分隔符,因此通常的做法是在字符串中使用一个分隔符,以提高可读性。例如:<code>'foo,bar,\n"hihi","hi\nhi"'</code>。关于这个问题。。。在</p>
<p>您可能需要python regexp模块:<a href="http://docs.python.org/library/re.html" rel="nofollow">re</a>。
特别是,替换函数就是你想要的。有很多方法可以做到这一点,但是一个快速的选择是使用一个regexp来标识<code>""</code>子字符串,然后调用一个helper函数从这些子字符串中除去任何<code>\n</code>。。。在</p>
<pre><code>import re
def helper(match):
return match.group().replace("\n","")
input = 'foo,bar,\n"hihi","hi\nhi"'
result = re.sub('(".*?")', helper, input, flags=re.S)
</code></pre>