fork(2) download
  1. import java.io.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String input = "\"abcd\",\"12345\",\"success,1234,out\",,\"hai\"";
  9. Pattern pattern = Pattern.compile("(\"[^\"]+\")|(?<=,)(,)");
  10. Matcher matcher = pattern.matcher(input);
  11. int col = 1;
  12. while (matcher.find()) {
  13. if (matcher.group(1) != null) {
  14. System.out.println("Column " + col + ": " + matcher.group(1));
  15. col++;
  16. } else if (matcher.group(2) != null) {
  17. System.out.println("Column " + col + ": null");
  18. col++;
  19. }
  20. }
  21. }
  22. }
  23.  
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
Column 1: "abcd"
Column 2: "12345"
Column 3: "success,1234,out"
Column 4: null
Column 5: "hai"