Ruby: How can I process a CSV file with “bad commas”?

后端 未结 4 1329
野趣味
野趣味 2021-01-23 16:10

I need to process a CSV file from FedEx.com containing shipping history. Unfortunately FedEx doesn\'t seem to actually test its CSV files as it doesn\'t quote strings that have

4条回答
  •  旧巷少年郎
    2021-01-23 16:56

    you can use a negative lookahead

    >> "foo,bar,baz,pop, blah,foobar".split(/,(?![ \t])/)
    => ["foo", "bar", "baz", "pop, blah", "foobar"]
    

提交回复
热议问题