Regular expression to find unescaped double quotes in CSV file

后端 未结 5 718
盖世英雄少女心
盖世英雄少女心 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:32

    For single-line matches:

    ^("[^"]*"\s*,\s*)*"[^"]*""[^"]*"
    

    or for multi-line:

    (^|\r\n)("[^\r\n"]*"\s*,\s*)*"[^\r\n"]*""[^\r\n"]*"
    

    Edit/Note: Depending on the regex engine used, you could use lookbehinds and other stuff to make the regex leaner. But this should work in most regex engines just fine.

提交回复
热议问题