fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String st = "'test1, test2','test3, test4',test5,'test6, test7',test8";
  10. Pattern p = Pattern.compile("('[^']*'|[^,]*)(?:,?)");
  11. Matcher m = p.matcher(st);
  12. while (m.find()) {
  13. System.out.println(m.group(1));
  14. }
  15. }
  16. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
'test1, test2'
'test3, test4'
test5
'test6, test7'
test8