Regular expression to find unescaped double quotes in CSV file

后端 未结 5 673
盖世英雄少女心
盖世英雄少女心 2021-01-03 06:00

What would a regular expression be to find sets of 2 unescaped double quotes that are contained in columns set off by double quotes in a CSV file?

Not a matc

5条回答
  •  再見小時候
    2021-01-03 06:25

    Try this:

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

    Explanation:

    (?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
    

    So, in plain English: "match two successive double quotes, only if they DON'T have a comma or end-of-the-line ahead of them with optionally spaces and tabs in between".

    (i) besides being the normal start-of-the-string and end-of-the-string meta characters.

提交回复
热议问题