相关疑难解决方法(0)

Python Regex Engine - "look-behind需要固定宽度模式"错误

我试图在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)

所以基本上我要做的就是

替换所有'''

  1. 前面没有行开头或逗号(和)
  2. 后面没有逗号或行尾

与'""'

为此,我使用下面的正则表达式

(?<!^|,)"(?!,|$)
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)

python regex

24
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

regex ×1