It's easier to show some code
I have the following:
scala> val a = """op1,"op2.1,op2.2",,op4""".split(",")
a: Array[java.lang.String] = Array(op1, "op2.1, op2.2", "", op4)
scala> a.foreach( println )
op1
"op2.1
op2.2"
op4
I'd like to get
scala> val a = """op1,"op2.1,op2.2",,op4""".split(",")
a: Array[java.lang.String] = Array(op1, "op2.1, op2.2", "", op4)
scala> a.foreach( println )
op1
op2.1, op2.2
op4
But I can't figure out what regular expression to use to split the string
-- edit --
I found the answer in this question: Java: splitting a comma-separated string but ignoring commas in quotes
最佳答案
使用此正则表达式拆分,它应该可以工作:,(?=([^\"]*\"[^\"]*\")*[^\"]*$)
关于regex - scala:按逗号分隔字符串,忽略引号之间的逗号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13335651/