regular expression should split , that are contained outside the double quotes in a CSV file?

前端 未结 4 827
情话喂你
情话喂你 2021-01-26 10:00

This is the sample

\"abc\",\"abcsds\",\"adbc,ds\",\"abc\"

Output should be

abc
abcsds
adbc,ds
abc
4条回答
  •  渐次进展
    2021-01-26 10:21

    If you can be sure there are no inner, escaped quotes, then I guess it's ok to use a regular expression for this. However, most modern languages already have proper CSV parsers.

    Use a proper parser is the correct answer to this. Text::CSV for Perl, for example.

    However, if you're dead set on using regular expressions, I'd suggest you "borrow" from some sort of module, like this one: http://metacpan.org/pod/Regexp::Common::balanced

提交回复
热议问题