【发布时间】:2011-04-25 09:17:19
【问题描述】:
我以 CSV 文件中的这一行为例:
2412,21,"Which of the following is not found in all cells?","Curriculum","Life and Living Processes, Life Processes",,,1,0,"endofline"
我想把它拆分成一个数组。直接的想法是只用逗号分割,但有些字符串中有逗号,例如“Life and Living Processes, Life Processes”,这些应该作为单个元素保留在数组中。另请注意,中间有两个逗号 - 我想将它们作为空字符串。
也就是说,我想要得到的数组是
[2412,21,"Which of the following is not found in all cells?","Curriculum","Life and Living Processes, Life Processes","","",1,0,"endofline"]
我可以想到涉及 eval 的 hacky 方式,但我希望有人能想出一个干净的正则表达式来做到这一点......
干杯,最大
【问题讨论】:
-
这是一个完美的例子,说明从字符串中提取数据所涉及的所有内容并非都是正则表达式的工作。