我试图在CSV格式的字符串中处理未匹配的双引号.
确切地说,
"It "does "not "make "sense", Well, "Does "it"
Run Code Online (Sandbox Code Playgroud)
应该更正为
"It" "does" "not" "make" "sense", Well, "Does" "it"
Run Code Online (Sandbox Code Playgroud)
所以基本上我要做的就是
替换所有'''
- 前面没有行开头或逗号(和)
- 后面没有逗号或行尾
与'""'
为此,我使用下面的正则表达式
(?<!^|,)"(?!,|$)
Run Code Online (Sandbox Code Playgroud)
问题是,虽然红宝石正则表达式引擎(http://www.rubular.com/)都能够解析正则表达式,蟒蛇正则表达式引擎(https://pythex.org/,http://www.pyregex.com/)抛出以下错误
Invalid regular expression: look-behind requires fixed-width pattern
Run Code Online (Sandbox Code Playgroud)
并且使用python 2.7.3它会抛出
sre_constants.error: look-behind requires fixed-width pattern
Run Code Online (Sandbox Code Playgroud)
谁能告诉我这里有什么烦恼?
================================================== ================================
在Tim的回应之后,我获得了多行字符串的以下输出
>>> str = """ "It "does "not "make "sense", Well, "Does "it"
... "It "does "not "make "sense", Well, "Does "it"
... "It "does "not "make "sense", Well, …Run Code Online (Sandbox Code Playgroud)