I have the following string:
s = "XIDJIJFHD8","Gothika","a0KU000000JMYCrMAP","USA","English","Sub & Audio","VOD","SD","01/01/2011 00:00:00.000000","12/31/2049 00:00:00.000000",,"Confirmed",,,,"Feature",,"2003-11-21","2004-03-23",,"R","for violence, brief language and nudity.","2024863","6000008953",,,"10.5240/A6FC-02AE-8093-3B05-6240-T","10.5240/D052-B470-0D01-25DF-DA91-4","2024863_6000008953","idwb:2024863_6000008953","CA-0000950613"
I need to convert it to 'pipe-separated'. Fields are enclosed with quotations "
, though if a field is empty, it won't have anything. The number of |
in the final output should be 31. Here is what I have so far:
re.sub(r'(\,|\")(,)(,|\")', '|', s)
However, the length of the above has only 23. What would the correct regex be?
Or, even better, maybe I could just do it directly in the csv module. Something like:
string_with_pipes = csv.write(s, delimiter="|")
Note that I just want to get a modified string, not actually save a file.