fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.stream.*;
  5. import java.util.regex.*;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String str = "(A,1),(Y,4),(F,5)";
  12. Pattern filerRegx = Pattern.compile("\\(\\s*([^()]*)\\s*\\)");
  13. Matcher regexMatcher = filerRegx.matcher(str);
  14. System.out.println( Stream.of(str.split(",")).
  15. filter(s -> regexMatcher.find() && regexMatcher.group(1) != null).
  16. map(r -> new String(regexMatcher.group(1))).
  17. collect(Collectors.toList()) );
  18. }
  19. }
Success #stdin #stdout 0.13s 4386816KB
stdin
Standard input is empty
stdout
[A,1, Y,4, F,5]