regex to split line (csv file)

后端 未结 7 1823
予麋鹿
予麋鹿 2020-12-03 12:37

I am not good in regex. Can some one help me out to write regex for me?

I may have values like this while reading csv file.

\"Artist,Name\",Album,12-SCS
\         


        
7条回答
  •  眼角桃花
    2020-12-03 13:03

    Regex might get overly complex here. Split the line on commas, and then iterate over the resultant bits and concatenate them where "the number of double quotes in the concatenated string" is not even.

    "hello,this",is,"a ""test"""

    ...split...

    "hello | this" | is | "a ""test"""

    ...iterate and merge 'til you've an even number of double quotes...

    "hello,this" - even number of quotes (note comma removed by split inserted between bits)

    is - even number of quotes

    "a ""test""" - even number of quotes

    ...then strip of leading and trailing quote if present and replace "" with ".

提交回复
热议问题