使用 decode// vs. regex 删除这一行

我有下一行,我正试图弄清楚如何最好地删除它。

在我得到这个输入的情况下,决定必须有些灵活性 API, 我不能绝对确定符号的当前结构 /
\n

不像
\r

/ 总会有相同的。


'"If it ain\'t broke, don\'t fix it." \nWent in for a detailed car wash.\nThe attendants raved-up my engine when taking the car into
the tunnel. NOTE: my car is...'


这 regex 似乎他应该工作:


text_excerpt = re.sub/r'[\s"\\]', ' ', raw_text_excerpt/.strip//


我也读过这个
decode//

能行得通 /一般来说,这将是最好的解决方案/.


raw_text_excerpt.decode/'string_unescape'/


我尝试了这样的东西,但没有什么出来。 你有一些想法吗? 在这里更好 regex?
已邀请:

快网

赞同来自:

你正在寻找的编解码器 - 这是
string-escape

:


>>> print "\\'".decode/"string-escape"/
'


我不确定他们添加了哪个版本,虽然 ... 也许你使用它不是的旧版本。 我正在奔跑:


Python 2.6.6 /r266:84292, Mar 25 2011, 19:36:32/ 
[GCC 4.5.2] on linux2

要回复问题请先登录注册