fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String line = "\"One\"; \"Two\"; \"Three\"; \"Four\"";
  12. String regexp = "(?<delim>[^\\w\n\"']|^)(?<space> ?)(?:(?<quote>[\"']).*?\\k<quote>|[^\\s,]+)(?=\\k<delim>?)";
  13. Pattern pattern = Pattern.compile(regexp);
  14. Matcher matcher = pattern.matcher(line);
  15. while (matcher.find()) {
  16. System.out.println("Match value: " + matcher.group());
  17. System.out.println("Delim: " + matcher.group("delim"));
  18. System.out.println("Quote: " + matcher.group("quote"));
  19. }
  20. }
  21. }
Success #stdin #stdout 0.06s 320576KB
stdin
Standard input is empty
stdout
Match value: "One"
Delim: 
Quote: "
Match value: ; "Two"
Delim: ;
Quote: "
Match value: ; "Three"
Delim: ;
Quote: "
Match value: ; "Four"
Delim: ;
Quote: "