-1

I'm trying to split the following strings by comma but the name field with the quotations is causing a problem. What would be the best Regex pattern to handle this use case?

Below is a sample of the text.

7,"U.S. Representative, Dist I - N",7,"OF",,367,20,"GRIFFIN, Calvin (G)",1,"",314,45,193,552
8,"U.S. Representative, Dist I - D",8,"OF",,3991,24,"HANABUSA, Colleen Wakako",2,"",43493,4472,26057,74022
8,"U.S. Representative, Dist I - D",8,"OF",,3991,22,"AHU ISA, Lei (Leinaala)",1,"",6690,741,4087,11518
Daria Pydorenko
  • 1,754
  • 2
  • 18
  • 45
Trey Balut
  • 1,355
  • 3
  • 19
  • 39
  • 10
    Don't roll your own CSV parser. Use an already established library, they have solved all the issues you will encounter already – maccettura Aug 13 '18 at 15:21
  • @maccettura i agree with your answer. You might want to link a few good csv parsers so that your answer becomes a full solution. – Juls Aug 13 '18 at 15:26
  • 1
    @Juls It is not an answer to question, hence a comment. Very good advice, though. For the CSV libs: I think I remember that there was a website, where you can enter some words and it has a database with possible websites that match ;) – Fildor Aug 13 '18 at 15:29
  • https://stackoverflow.com/questions/18144431/regex-to-split-a-csv – Dmitry Bychenko Aug 13 '18 at 15:33
  • https://stackoverflow.com/questions/3507498/reading-csv-files-using-c-sharp – PaulF Aug 13 '18 at 15:33

1 Answers1

0

I agree with the comments that refer that you should go with a csv parser solution but if you really intend to use regex here is a good start point:

"[^"\r\n]*"|'[^'\r\n]*'|[^,\r\n]*

You can test it here.

Rui Fernandes
  • 270
  • 1
  • 11