fork(9) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String s = " \" ab cd \" , \" efgh,ijk.\", 4,\"lmno\"";
  9. Matcher m = Pattern.compile("\\s*(?:\"[^\"]*\"|(?:^|(?<=,))[^,]*)").matcher(s);
  10. while (m.find()) {
  11. System.out.println(m.group().replaceAll("^\\s*\"?\\s*(.*?)\\s*\"?\\s*$", "$1"));
  12. }
  13. }
  14. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
ab  cd
efgh,ijk.
4
lmno