0

I have a simple requirement to split lines in a file. The file is csv format and the dilimitter is ','. Not even a regexp is needed, a simple split(',') will do for most cases.

However, I have some lines go like,

Sale,8/18/2017,"99 RANCH #1601 001658500 - EDISON, NJ",-225.07,Supplie

In which case I need the code to detect the " first, ignore the comma in it and treat the part between " as a whole component.

How do we go about to deal with this with regexp? I am using Python3.

J.E.Y
  • 1,173
  • 2
  • 15
  • 37
  • Can't you just read the csv in with the csv module? I think commas withing quotes aren't counted as delimiters – SuperStew Dec 07 '17 at 21:09
  • 1
    Why not use the `csv` module? It already handles these (and many other) cases correctly. – cco Dec 07 '17 at 21:10

0 Answers0