0

I have data like below

111,222,"33,44,55",666,"77,88","99"

it is delimited by , and also placed between quote character to ignore delimiter inside data

String input = "111,222,\"33,44,55\",666,\"77,88\",\"99\"";     
String[] splits = input.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
  for(String s : splits){
        System.out.println(s);
   }

Above code is working fine and returns 111,222,"33,44,55",666,"77,88","99"

but now the data itself contain quote character

111,222,"33,"44,55",666,"77,88","99"

I want to get back 111,222,"33,"44,55",666,77,88,99 but I get 111,222,"33,"44,55",666,"77,88","99"

String input = "111,222,\"33,\"44,55\",666,\"77,88\",\"99\"";

the pattern is not working correctly can someone help me to get the data if quote character is part of data

jhamon
  • 3,603
  • 4
  • 26
  • 37
Shalaj
  • 579
  • 8
  • 19
  • 6
    Have you looked at using a CSV parser for this? Like opencsv for example – Joakim Danielson Sep 19 '19 at 09:12
  • You may consider a 2-step approach: 1) encode all `"` inside `"` after a `,` (or start of string) and `"` before a `,` (or end of string) as, say, `"` and then 2) split using the current regex. See [this Java 9+ demo](http://ideone.com/aaYcbi). – Wiktor Stribiżew Sep 19 '19 at 09:29
  • I’d not use `split`. See [this answer](https://stackoverflow.com/a/58013294/2711488)… – Holger Sep 19 '19 at 14:29

0 Answers0