正则表达式用引号和逗号分隔

时间:2018-08-13 15:20:11

标签: c# regex

我正在尝试用comma分割以下字符串,但是带有quotations的名称字段引起了问题。处理此用例的最佳Regex模式是什么?

下面是文本示例。

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

1 个答案:

答案 0 :(得分:0)

我同意以下意见,即您应该使用csv解析器解决方案,但如果您确实打算使用regex,则这里是一个很好的起点:

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

您可以here对其进行测试。