fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String strings[] = {
  12. "\"abc\"-\"123\"-\"zxc1\"",
  13. "\"abc\"-\"123\"-\"zxc2",
  14. "\"abc\"-\"123\"-zxc3\"",
  15. "abc\"-\"123\"-\"zxc4\"",
  16. "\"abc\"-\"123\"-\"zxc5",
  17. "abc\"-\"123\"-\"zxc6\"",
  18. "abc-\"123\"-\"zxc7\"",
  19. "\"abc\"-\"123\"-zxc8"
  20. };
  21. String regex = "\\G(\"[^\"]*\")(?=(?:-\"[^\"]*\")*$)(?:-|$)";
  22. Pattern pattern = Pattern.compile(regex);
  23. for (String s : strings) {
  24. Matcher matcher = pattern.matcher(s);
  25.  
  26. while (matcher.find()) {
  27. for (int i = 1; i <= matcher.groupCount(); i++) {
  28. System.out.println(matcher.group(i));
  29. }
  30. }
  31. }
  32. }
  33. }
Success #stdin #stdout 0.11s 33672KB
stdin
Standard input is empty
stdout
"abc"
"123"
"zxc1"