fork(1) 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 #stderr 0.04s 711168KB
stdin
Standard input is empty
stdout
Match value: One
Delim: 
Quote: null
Match value: ,Two
Delim: ,
Quote: null
Match value: ,Three
Delim: ,
Quote: null
Match value: ,Four
Delim: ,
Quote: null
stderr
Java HotSpot(TM) Client VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes