Possible Duplicate:
Java: splitting a comma-separated string but ignoring commas in quotes
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
Split with this regexp, it should work: ,(?=([^\"]*\"[^\"]*\")*[^\"]*$)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With