查找 CSV 文件中由双引号引起的列中包含的 2 个未转义双引号的集合是什么正则表达式?

不匹配:

"asdf","asdf"
"", "asdf"
"asdf", ""
"adsf", "", "asdf"

匹配项:
"asdf""asdf", "asdf"
"asdf", """asdf"""
"asdf", """"

最佳答案

试试这个:

(?m)""(?![ \t]*(,|$))

解释:
(?m)       // enable multi-line matching (^ will act as the start of the line and $ will act as the end of the line (i))
""         // match two successive double quotes
(?!        // start negative look ahead
  [ \t]*   //   zero or more spaces or tabs
  (        //   open group 1
    ,      //     match a comma
    |      //     OR
    $      //     the end of the line or string
  )        //   close group 1
)          // stop negative look ahead

因此,用简单的英语: “匹配两个连续的双引号,仅当它们前面没有逗号或行尾且中间有可选的空格和制表符时”

(i) 除了是正常的字符串开头和字符串结尾元字符之外。

关于regex - 在 CSV 文件中查找未转义双引号的正则表达式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1601780/

10-17 01:01